/
da.go
94 lines (78 loc) · 3.15 KB
/
da.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package da
import (
"github.com/gridironOne/furyint/log"
"github.com/gridironOne/furyint/store"
"github.com/gridironOne/furyint/types"
)
// StatusCode is a type for DA layer return status.
// TODO: define an enum of different non-happy-path cases
// that might need to be handled by Dymint independent of
// the underlying DA chain.
type StatusCode uint64
// Data Availability return codes.
const (
StatusUnknown StatusCode = iota
StatusSuccess
StatusTimeout
StatusError
)
// Client defines all the possible da clients
type Client string
// Data availability clients
const (
Mock Client = "mock"
Celestia Client = "celestia"
)
// BaseResult contains basic information returned by DA layer.
type BaseResult struct {
// Code is to determine if the action succeeded.
Code StatusCode
// Message may contain DA layer specific information (like DA block height/hash, detailed error message, etc)
Message string
// DAHeight informs about a height on Data Availability Layer for given result.
DAHeight uint64
}
// ResultSubmitBatch contains information returned from DA layer after block submission.
type ResultSubmitBatch struct {
BaseResult
// Not sure if this needs to be bubbled up to other
// parts of Dymint.
// Hash hash.Hash
}
// ResultCheckBatch contains information about block availability, returned from DA layer client.
type ResultCheckBatch struct {
BaseResult
// DataAvailable is the actual answer whether the block is available or not.
// It can be true if and only if Code is equal to StatusSuccess.
DataAvailable bool
}
// ResultRetrieveBatch contains batch of blocks returned from DA layer client.
type ResultRetrieveBatch struct {
BaseResult
// Block is the full block retrieved from Data Availability Layer.
// If Code is not equal to StatusSuccess, it has to be nil.
Batches []*types.Batch
}
// DataAvailabilityLayerClient defines generic interface for DA layer block submission.
// It also contains life-cycle methods.
type DataAvailabilityLayerClient interface {
// Init is called once to allow DA client to read configuration and initialize resources.
Init(config []byte, kvStore store.KVStore, logger log.Logger) error
// Start is called once, after Init. It's implementation should start operation of DataAvailabilityLayerClient.
Start() error
// Stop is called once, when DataAvailabilityLayerClient is no longer needed.
Stop() error
// SubmitBatch submits the passed in block to the DA layer.
// This should create a transaction which (potentially)
// triggers a state transition in the DA layer.
SubmitBatch(batch *types.Batch) ResultSubmitBatch
// CheckBatchAvailability queries DA layer to check data availability of block corresponding at given height.
CheckBatchAvailability(dataLayerHeight uint64) ResultCheckBatch
GetClientType() Client
}
// BatchRetriever is additional interface that can be implemented by Data Availability Layer Client that is able to retrieve
// block data from DA layer. This gives the ability to use it for block synchronization.
type BatchRetriever interface {
// RetrieveBatches returns blocks at given data layer height from data availability layer.
RetrieveBatches(dataLayerHeight uint64) ResultRetrieveBatch
}