diff --git a/da/celestia/celestia.go b/da/celestia/celestia.go index 4af7f40d2..71a189e6b 100644 --- a/da/celestia/celestia.go +++ b/da/celestia/celestia.go @@ -21,12 +21,6 @@ import ( pb "github.com/dymensionxyz/dymint/types/pb/dymint" ) -const ( - defaultTxPollingRetryDelay = 20 * time.Second - defaultSubmitRetryDelay = 10 * time.Second - defaultTxPollingAttempts = 5 -) - type CNCClientI interface { SubmitPFD(ctx context.Context, namespaceID [8]byte, blob []byte, fee int64, gasLimit uint64) (*cnc.TxResponse, error) NamespacedShares(ctx context.Context, namespaceID [8]byte, height uint64) ([][]byte, error) @@ -50,16 +44,6 @@ type DataAvailabilityLayerClient struct { var _ da.DataAvailabilityLayerClient = &DataAvailabilityLayerClient{} var _ da.BatchRetriever = &DataAvailabilityLayerClient{} -// Config stores Celestia DALC configuration parameters. -type Config struct { - BaseURL string `json:"base_url"` - AppNodeURL string `json:"app_node_url"` - Timeout time.Duration `json:"timeout"` - Fee int64 `json:"fee"` - GasLimit uint64 `json:"gas_limit"` - NamespaceID [8]byte `json:"namespace_id"` -} - // WithCNCClient sets CNC client. func WithCNCClient(client CNCClientI) da.Option { return func(daLayerClient da.DataAvailabilityLayerClient) { @@ -99,16 +83,20 @@ func WithSubmitRetryDelay(delay time.Duration) da.Option { func (c *DataAvailabilityLayerClient) Init(config []byte, pubsubServer *pubsub.Server, kvStore store.KVStore, logger log.Logger, options ...da.Option) error { c.logger = logger - if len(config) > 0 { - err := json.Unmarshal(config, &c.config) - if err != nil { - return err - } + if len(config) <= 0 { + return errors.New("config is empty") + } + err := json.Unmarshal(config, &c.config) + if err != nil { + return err + } + err = (&c.config).InitNamespaceID() + if err != nil { + return err } c.pubsubServer = pubsubServer // Set defaults - var err error c.txPollingRetryDelay = defaultTxPollingRetryDelay c.txPollingAttempts = defaultTxPollingAttempts c.submitRetryDelay = defaultSubmitRetryDelay diff --git a/da/celestia/config.go b/da/celestia/config.go new file mode 100644 index 000000000..a3be4ad0a --- /dev/null +++ b/da/celestia/config.go @@ -0,0 +1,43 @@ +package celestia + +import ( + "encoding/hex" + "time" +) + +const ( + defaultTxPollingRetryDelay = 20 * time.Second + defaultSubmitRetryDelay = 10 * time.Second + defaultTxPollingAttempts = 5 +) + +// Config stores Celestia DALC configuration parameters. +type Config struct { + BaseURL string `json:"base_url"` + AppNodeURL string `json:"app_node_url"` + Timeout time.Duration `json:"timeout"` + Fee int64 `json:"fee"` + GasLimit uint64 `json:"gas_limit"` + NamespaceIDStr string `json:"namespace_id"` + NamespaceID [8]byte `json:"-"` +} + +var CelestiaDefaultConfig = Config{ + BaseURL: "http://127.0.0.1:26659", + AppNodeURL: "", + Timeout: 30 * time.Second, + Fee: 20000, + GasLimit: 20000000, + NamespaceIDStr: "000000000000ffff", + NamespaceID: [8]byte{0, 0, 0, 0, 0, 0, 255, 255}, +} + +func (c *Config) InitNamespaceID() error { + // Decode NamespaceID from string to byte array + namespaceBytes, err := hex.DecodeString(c.NamespaceIDStr) + if err != nil { + return err + } + copy(c.NamespaceID[:], namespaceBytes) + return nil +} diff --git a/da/da_test.go b/da/da_test.go index 076f71098..3cf52d0b8 100644 --- a/da/da_test.go +++ b/da/da_test.go @@ -37,16 +37,26 @@ func TestLifecycle(t *testing.T) { t.Skip("TODO") } t.Run(dalc, func(t *testing.T) { - doTestLifecycle(t, registry.GetClient(dalc)) + doTestLifecycle(t, dalc) }) } } -func doTestLifecycle(t *testing.T, dalc da.DataAvailabilityLayerClient) { +func doTestLifecycle(t *testing.T, daType string) { + var err error require := require.New(t) pubsubServer := pubsub.NewServer() pubsubServer.Start() - err := dalc.Init([]byte{}, pubsubServer, nil, test.NewLogger(t)) + + dacfg := []byte{} + dalc := registry.GetClient(daType) + + if daType == "celestia" { + dacfg, err = json.Marshal(celestia.CelestiaDefaultConfig) + require.NoError(err) + } + + err = dalc.Init(dacfg, pubsubServer, nil, test.NewLogger(t)) require.NoError(err) err = dalc.Start()