1+ // Rollkit DA layer client for Sugondat.
2+ //
3+ // This adapter implements the `DataAvailabilityLayerClient` and `BlockRetriever` interfaces. It
4+ // connects to a running sugondat-shim RPC server and uses it to submit and retrieve blocks.
5+ //
6+ // The intended usage is to add this module to your application and call `Register()`. This will
7+ // make the sugondat adapter available to Rollkit.
8+ //
9+ // To start your rollkit rollup with this adapter, you will need to run your blockchain with the
10+ // following arguments (assuming `gmd`).
11+ //
12+ // ```
13+ //
14+ // gmd \
15+ // --rollkit.da_layer sugondat
16+ // --rollkit.da_config='{"base_url":"http://localhost:10995","namespace":"0102030405060708"}'
17+ //
18+ // ```
119package sugondat
220
321import (
@@ -12,12 +30,15 @@ import (
1230 "github.com/rollkit/rollkit/types"
1331)
1432
33+ // A data package that contains the rollup specific data.
1534type Blob struct {
16- Data []byte `json:"data"`
35+ Data []byte `json:"data"` // base64 encoded blob data.
1736}
1837
38+ // Declaration of JSON-RPC API for sugondat-shim.
1939type SugondatAPI struct {
2040 // Retrieves the blobs at the given height from the data availability layer at the given namespace.
41+ // Returns the blobs.
2142 Retrieve func (string , uint64 ) ([]* Blob , error )
2243 // Submits the given blobs to the data availability layer at the given namespace.
2344 // Returns the height of the block that contains the blobs.
@@ -29,6 +50,7 @@ type RpcClient struct {
2950 api SugondatAPI
3051}
3152
53+ // Main adapter struct.
3254type DataAvailabilityLayerClient struct {
3355 logger log.Logger
3456 config Config
@@ -38,11 +60,14 @@ type DataAvailabilityLayerClient struct {
3860var _ da.DataAvailabilityLayerClient = & DataAvailabilityLayerClient {}
3961var _ da.BlockRetriever = & DataAvailabilityLayerClient {}
4062
63+ // Configuration of the Sugondat adapter.
4164type Config struct {
42- BaseURL string `json:"base_url"`
43- Namespace string `json:"namespace"`
65+ BaseURL string `json:"base_url"` // The base URL of the sugondat-shim RPC server.
66+ Namespace string `json:"namespace"` // HEX encoded namespace ID. Cannot be empty.
4467}
4568
69+ // Register the `sugondat` adapter with the da adapter registry. Must be called to make the adapter
70+ // available via `--da.layer sugondat`.
4671func Register () error {
4772 return registry .Register ("sugondat" , func () da.DataAvailabilityLayerClient {
4873 return & DataAvailabilityLayerClient {}
@@ -60,6 +85,9 @@ func (c *DataAvailabilityLayerClient) Init(namespaceID types.NamespaceID, config
6085 return nil
6186}
6287
88+ // Starts the RPC client.
89+ //
90+ // Expected to be called before `SubmitBlocks` or `RetrieveBlocks`.
6391func (c * DataAvailabilityLayerClient ) Start () error {
6492 c .logger .Info ("starting Sugondat Data Availability Layer Client" , "baseURL" , c .config .BaseURL )
6593 closer , err := jsonrpc .NewClient (context .Background (), c .config .BaseURL , "Rollkit" , & c .rpc .api , nil )
@@ -70,6 +98,7 @@ func (c *DataAvailabilityLayerClient) Start() error {
7098 return nil
7199}
72100
101+ // Tears down the RPC client.
73102func (c * DataAvailabilityLayerClient ) Stop () error {
74103 c .logger .Info ("stopping Sugondat Data Availability Layer Client" )
75104 c .rpc .closer ()
0 commit comments