forked from cosmos/ibc-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Data Availability Submission API (cosmos#71)
Add interface for Data Availability layer This is the initial part of the interface, containing life-cycle methods and method for submission of block. It also contains simple mock implementation that can be used in tests.
- Loading branch information
Showing
5 changed files
with
154 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package da | ||
|
||
import ( | ||
"github.com/lazyledger/optimint/log" | ||
"github.com/lazyledger/optimint/types" | ||
) | ||
|
||
// TODO define an enum of different non-happy-path cases | ||
// that might need to be handled by Optimint independent of | ||
// the underlying DA chain. | ||
type StatusCode uint64 | ||
|
||
const ( | ||
StatusUnknown StatusCode = iota | ||
StatusSuccess | ||
StatusTimeout | ||
StatusError | ||
) | ||
|
||
type ResultSubmitBlock struct { | ||
// Code is to determine if the action succeeded. | ||
Code StatusCode | ||
// Message may contain DA layer specific information (like detailed error message) | ||
Message string | ||
// Not sure if this needs to be bubbled up to other | ||
// parts of Optimint. | ||
// Hash hash.Hash | ||
} | ||
|
||
type DataAvailabilityLayerClient interface { | ||
// Init is called once to allow DA client to read configuration and initialize resources. | ||
Init(config []byte, logger log.Logger) error | ||
|
||
Start() error | ||
Stop() error | ||
|
||
// SubmitBlock submits the passed in block to the DA layer. | ||
// This should create a transaction which (potentially) | ||
// triggers a state transition in the DA layer. | ||
SubmitBlock(block *types.Block) ResultSubmitBlock | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package mock | ||
|
||
import ( | ||
"github.com/lazyledger/optimint/da" | ||
"github.com/lazyledger/optimint/log" | ||
"github.com/lazyledger/optimint/types" | ||
) | ||
|
||
type MockDataAvailabilityLayerClient struct { | ||
logger log.Logger | ||
|
||
Blocks []*types.Block | ||
} | ||
|
||
// Init is called once to allow DA client to read configuration and initialize resources. | ||
func (m *MockDataAvailabilityLayerClient) Init(config []byte, logger log.Logger) error { | ||
m.logger = logger | ||
return nil | ||
} | ||
|
||
func (m *MockDataAvailabilityLayerClient) Start() error { | ||
m.logger.Debug("Mock Data Availability Layer Client starting") | ||
return nil | ||
} | ||
|
||
func (m *MockDataAvailabilityLayerClient) Stop() error { | ||
m.logger.Debug("Mock Data Availability Layer Client stopped") | ||
return nil | ||
} | ||
|
||
// SubmitBlock submits the passed in block to the DA layer. | ||
// This should create a transaction which (potentially) | ||
// triggers a state transition in the DA layer. | ||
func (m *MockDataAvailabilityLayerClient) SubmitBlock(block *types.Block) da.ResultSubmitBlock { | ||
m.Blocks = append(m.Blocks, block) | ||
|
||
return da.ResultSubmitBlock{ | ||
Code: da.StatusSuccess, | ||
Message: "OK", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# ADR 005: Data Availability Client Interface | ||
|
||
## Changelog | ||
|
||
- 2021.04.30: Initial draft | ||
- 2021.06.03: Init method added | ||
|
||
## Context | ||
|
||
Optimint requires data availability layer. Different implementations are expected. | ||
|
||
## Alternative Approaches | ||
|
||
> This section contains information around alternative options that are considered before making a decision. It should contain a explanation on why the alternative approach(es) were not chosen. | ||
## Decision | ||
|
||
Defined interface should be very generic. | ||
Interface should consist of 4 methods: `Init`, `Start`, `Stop`, `SubmitBlock`. | ||
All the details are implementation-specific. | ||
|
||
## Detailed Design | ||
|
||
Definition of interface: | ||
```go | ||
type DataAvailabilityLayerClient interface { | ||
// Init is called once to allow DA client to read configuration and initialize resources. | ||
Init(config []byte, logger log.Logger) error | ||
|
||
Start() error | ||
Stop() error | ||
|
||
// SubmitBlock submits the passed in block to the DA layer. | ||
// This should create a transaction which (potentially) | ||
// triggers a state transition in the DA layer. | ||
SubmitBlock(block *types.Block) ResultSubmitBlock | ||
} | ||
|
||
// TODO define an enum of different non-happy-path cases | ||
// that might need to be handled by Optimint independent of | ||
// the underlying DA chain. | ||
type StatusCode uint64 | ||
|
||
const ( | ||
StatusSuccess StatusCode = iota | ||
StatusTimeout | ||
StatusError | ||
) | ||
``` | ||
> | ||
## Status | ||
|
||
Implemented | ||
|
||
## Consequences | ||
|
||
> This section describes the consequences, after applying the decision. All consequences should be summarized here, not just the "positive" ones. | ||
### Positive | ||
|
||
### Negative | ||
|
||
### Neutral | ||
|
||
## References | ||
|
||
> Are there any relevant PR comments, issues that led up to this, or articles referenced for why we made the given design choice? If so link them here! | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters