From 3cd61e021830288e926c7657180f24e34ada23d5 Mon Sep 17 00:00:00 2001 From: Michael Tsitrin <114929630+mtsitrin@users.noreply.github.com> Date: Mon, 8 Apr 2024 17:49:56 +0300 Subject: [PATCH] refactor: move logger interface to types (#633) --- block/manager.go | 84 +++++++++-------------- block/types.go | 16 +++++ da/avail/avail.go | 5 +- da/avail/avail_test.go | 4 +- da/celestia/celestia.go | 5 +- da/celestia/mock/server.go | 5 +- da/da.go | 3 +- da/grpc/grpc.go | 5 +- da/local/local.go | 5 +- mocks/settlement/settlement_layer.go | 2 +- p2p/client.go | 6 +- p2p/client_test.go | 4 +- p2p/gossip.go | 6 +- p2p/utils_test.go | 4 +- p2p/validator.go | 6 +- rpc/json/handler.go | 6 +- rpc/json/service.go | 8 +-- rpc/json/ws.go | 4 +- settlement/base.go | 5 +- settlement/dymension/dymension.go | 7 +- settlement/grpc/grpc.go | 7 +- settlement/local/local.go | 7 +- settlement/settlement.go | 3 +- state/executor.go | 5 +- log/test/loggers.go => testutil/logger.go | 2 +- {log => types}/logger.go | 2 +- utils/events.go | 4 +- 27 files changed, 104 insertions(+), 116 deletions(-) create mode 100644 block/types.go rename log/test/loggers.go => testutil/logger.go (99%) rename {log => types}/logger.go (93%) diff --git a/block/manager.go b/block/manager.go index 1f8833a5f..7195b9323 100644 --- a/block/manager.go +++ b/block/manager.go @@ -8,8 +8,6 @@ import ( "sync/atomic" "time" - // Importing the general purpose Cosmos blockchain client - "code.cloudfoundry.org/go-diodes" "github.com/dymensionxyz/dymint/node/events" @@ -24,7 +22,6 @@ import ( "github.com/dymensionxyz/dymint/config" "github.com/dymensionxyz/dymint/da" - "github.com/dymensionxyz/dymint/log" "github.com/dymensionxyz/dymint/mempool" "github.com/dymensionxyz/dymint/settlement" "github.com/dymensionxyz/dymint/state" @@ -32,71 +29,48 @@ import ( "github.com/dymensionxyz/dymint/types" ) -type blockSource string - -const ( - producedBlock blockSource = "produced" - gossipedBlock blockSource = "gossip" - daBlock blockSource = "da" -) - -type blockMetaData struct { - source blockSource - daHeight uint64 -} - // Manager is responsible for aggregating transactions into blocks. type Manager struct { - pubsub *pubsub.Server - - p2pClient *p2p.Client - - lastState types.State - - conf config.BlockManagerConfig - genesis *tmtypes.GenesisDoc - + // Configuration + conf config.BlockManagerConfig + genesis *tmtypes.GenesisDoc proposerKey crypto.PrivKey - store store.Store - executor *state.BlockExecutor + // Store and execution + store store.Store + lastState types.State + executor *state.BlockExecutor + // Clients and servers + pubsub *pubsub.Server + p2pClient *p2p.Client dalc da.DataAvailabilityLayerClient settlementClient settlement.LayerI - retriever da.BatchRetriever + // Data retrieval + retriever da.BatchRetriever + + // Synchronization syncTargetDiode diodes.Diode + syncTarget uint64 + isSyncedCond sync.Cond + // Block production shouldProduceBlocksCh chan bool produceEmptyBlockCh chan bool - - syncTarget uint64 - lastSubmissionTime int64 - batchInProcess atomic.Value - isSyncedCond sync.Cond - + lastSubmissionTime int64 + batchInProcess atomic.Value produceBlockMutex sync.Mutex applyCachedBlockMutex sync.Mutex - syncCache map[uint64]*types.Block - - logger log.Logger + // Logging + logger types.Logger + // Previous data prevBlock map[uint64]*types.Block prevCommit map[uint64]*types.Commit } -// getInitialState tries to load lastState from Store, and if it's not available it reads GenesisDoc. -func getInitialState(store store.Store, genesis *tmtypes.GenesisDoc, logger log.Logger) (types.State, error) { - s, err := store.LoadState() - if err == types.ErrNoStateFound { - logger.Info("failed to find state in the store, creating new state from genesis") - return types.NewFromGenesisDoc(genesis) - } - - return s, err -} - // NewManager creates new block Manager. func NewManager( proposerKey crypto.PrivKey, @@ -110,7 +84,7 @@ func NewManager( eventBus *tmtypes.EventBus, pubsub *pubsub.Server, p2pClient *p2p.Client, - logger log.Logger, + logger types.Logger, ) (*Manager, error) { proposerAddress, err := getAddress(proposerKey) @@ -144,7 +118,6 @@ func NewManager( retriever: dalc.(da.BatchRetriever), // channels are buffered to avoid blocking on input/output operations, buffer sizes are arbitrary syncTargetDiode: diodes.NewOneToOne(1, nil), - syncCache: make(map[uint64]*types.Block), isSyncedCond: *sync.NewCond(new(sync.Mutex)), batchInProcess: batchInProcess, shouldProduceBlocksCh: make(chan bool, 1), @@ -280,3 +253,14 @@ func (m *Manager) applyBlockCallback(event pubsub.Message) { func (m *Manager) getLatestBatchFromSL(ctx context.Context) (*settlement.ResultRetrieveBatch, error) { return m.settlementClient.RetrieveBatch() } + +// getInitialState tries to load lastState from Store, and if it's not available it reads GenesisDoc. +func getInitialState(store store.Store, genesis *tmtypes.GenesisDoc, logger types.Logger) (types.State, error) { + s, err := store.LoadState() + if err == types.ErrNoStateFound { + logger.Info("failed to find state in the store, creating new state from genesis") + return types.NewFromGenesisDoc(genesis) + } + + return s, err +} diff --git a/block/types.go b/block/types.go new file mode 100644 index 000000000..785e9a907 --- /dev/null +++ b/block/types.go @@ -0,0 +1,16 @@ +package block + +//TODO: move to types package + +type blockSource string + +const ( + producedBlock blockSource = "produced" + gossipedBlock blockSource = "gossip" + daBlock blockSource = "da" +) + +type blockMetaData struct { + source blockSource + daHeight uint64 +} diff --git a/da/avail/avail.go b/da/avail/avail.go index a5dd3e469..c3808205c 100644 --- a/da/avail/avail.go +++ b/da/avail/avail.go @@ -8,7 +8,6 @@ import ( "time" "github.com/avast/retry-go/v4" - "github.com/dymensionxyz/dymint/log" "github.com/gogo/protobuf/proto" "github.com/dymensionxyz/dymint/types" @@ -59,7 +58,7 @@ type DataAvailabilityLayerClient struct { client SubstrateApiI pubsubServer *pubsub.Server config Config - logger log.Logger + logger types.Logger ctx context.Context cancel context.CancelFunc txInclusionTimeout time.Duration @@ -99,7 +98,7 @@ func WithBatchRetryAttempts(attempts uint) da.Option { } // Init initializes DataAvailabilityLayerClient instance. -func (c *DataAvailabilityLayerClient) Init(config []byte, pubsubServer *pubsub.Server, kvStore store.KVStore, logger log.Logger, options ...da.Option) error { +func (c *DataAvailabilityLayerClient) Init(config []byte, pubsubServer *pubsub.Server, kvStore store.KVStore, logger types.Logger, options ...da.Option) error { c.logger = logger if len(config) > 0 { diff --git a/da/avail/avail_test.go b/da/avail/avail_test.go index c5f71d260..a7d64657f 100644 --- a/da/avail/avail_test.go +++ b/da/avail/avail_test.go @@ -7,8 +7,8 @@ import ( availtypes "github.com/centrifuge/go-substrate-rpc-client/v4/types" "github.com/dymensionxyz/dymint/da" "github.com/dymensionxyz/dymint/da/avail" - "github.com/dymensionxyz/dymint/log/test" mocks "github.com/dymensionxyz/dymint/mocks/da/avail" + "github.com/dymensionxyz/dymint/testutil" "github.com/dymensionxyz/dymint/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -133,7 +133,7 @@ func TestRetriveBatches(t *testing.T) { assert.NoError(err) // Start the DALC dalc := avail.DataAvailabilityLayerClient{} - err = dalc.Init(configBytes, pubsubServer, nil, test.NewLogger(t), options...) + err = dalc.Init(configBytes, pubsubServer, nil, testutil.NewLogger(t), options...) require.NoError(err) err = dalc.Start() require.NoError(err) diff --git a/da/celestia/celestia.go b/da/celestia/celestia.go index e9a41a2bd..de8c7bcbc 100644 --- a/da/celestia/celestia.go +++ b/da/celestia/celestia.go @@ -20,7 +20,6 @@ import ( "github.com/dymensionxyz/dymint/da" celtypes "github.com/dymensionxyz/dymint/da/celestia/types" - "github.com/dymensionxyz/dymint/log" "github.com/dymensionxyz/dymint/store" "github.com/dymensionxyz/dymint/types" pb "github.com/dymensionxyz/dymint/types/pb/dymint" @@ -32,7 +31,7 @@ type DataAvailabilityLayerClient struct { pubsubServer *pubsub.Server config Config - logger log.Logger + logger types.Logger ctx context.Context cancel context.CancelFunc rpcRetryDelay time.Duration @@ -72,7 +71,7 @@ func WithSubmitRetryDelay(delay time.Duration) da.Option { } // Init initializes DataAvailabilityLayerClient instance. -func (c *DataAvailabilityLayerClient) Init(config []byte, pubsubServer *pubsub.Server, kvStore store.KVStore, logger log.Logger, options ...da.Option) error { +func (c *DataAvailabilityLayerClient) Init(config []byte, pubsubServer *pubsub.Server, kvStore store.KVStore, logger types.Logger, options ...da.Option) error { c.logger = logger if len(config) <= 0 { diff --git a/da/celestia/mock/server.go b/da/celestia/mock/server.go index 5f2704d55..6e6045050 100644 --- a/da/celestia/mock/server.go +++ b/da/celestia/mock/server.go @@ -16,7 +16,6 @@ import ( "github.com/celestiaorg/go-cnc" "github.com/dymensionxyz/dymint/da" "github.com/dymensionxyz/dymint/da/local" - "github.com/dymensionxyz/dymint/log" "github.com/dymensionxyz/dymint/store" "github.com/dymensionxyz/dymint/types" ) @@ -26,11 +25,11 @@ type Server struct { da *local.DataAvailabilityLayerClient blockTime time.Duration server *http.Server - logger log.Logger + logger types.Logger } // NewServer creates new instance of Server. -func NewServer(blockTime time.Duration, logger log.Logger) *Server { +func NewServer(blockTime time.Duration, logger types.Logger) *Server { return &Server{ da: new(local.DataAvailabilityLayerClient), blockTime: blockTime, diff --git a/da/da.go b/da/da.go index 1cece95ba..23e0ebb1a 100644 --- a/da/da.go +++ b/da/da.go @@ -7,7 +7,6 @@ import ( "strings" "github.com/cometbft/cometbft/crypto/merkle" - "github.com/dymensionxyz/dymint/log" "github.com/dymensionxyz/dymint/store" "github.com/dymensionxyz/dymint/types" "github.com/rollkit/celestia-openrpc/types/blob" @@ -182,7 +181,7 @@ type ResultRetrieveBatch struct { // 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, pubsubServer *pubsub.Server, kvStore store.KVStore, logger log.Logger, options ...Option) error + Init(config []byte, pubsubServer *pubsub.Server, kvStore store.KVStore, logger types.Logger, options ...Option) error // Start is called once, after Init. It's implementation should start operation of DataAvailabilityLayerClient. Start() error diff --git a/da/grpc/grpc.go b/da/grpc/grpc.go index 07eaf55d3..8fb4bf20a 100644 --- a/da/grpc/grpc.go +++ b/da/grpc/grpc.go @@ -9,7 +9,6 @@ import ( "google.golang.org/grpc/credentials/insecure" "github.com/dymensionxyz/dymint/da" - "github.com/dymensionxyz/dymint/log" "github.com/dymensionxyz/dymint/store" "github.com/dymensionxyz/dymint/types" "github.com/dymensionxyz/dymint/types/pb/dalc" @@ -23,7 +22,7 @@ type DataAvailabilityLayerClient struct { conn *grpc.ClientConn client dalc.DALCServiceClient - logger log.Logger + logger types.Logger } // Config contains configuration options for DataAvailabilityLayerClient. @@ -43,7 +42,7 @@ var _ da.DataAvailabilityLayerClient = &DataAvailabilityLayerClient{} var _ da.BatchRetriever = &DataAvailabilityLayerClient{} // Init sets the configuration options. -func (d *DataAvailabilityLayerClient) Init(config []byte, _ *pubsub.Server, _ store.KVStore, logger log.Logger, options ...da.Option) error { +func (d *DataAvailabilityLayerClient) Init(config []byte, _ *pubsub.Server, _ store.KVStore, logger types.Logger, options ...da.Option) error { d.logger = logger if len(config) == 0 { d.config = DefaultConfig diff --git a/da/local/local.go b/da/local/local.go index a5d30f5dd..e5b271509 100644 --- a/da/local/local.go +++ b/da/local/local.go @@ -8,7 +8,6 @@ import ( "time" "github.com/dymensionxyz/dymint/da" - "github.com/dymensionxyz/dymint/log" "github.com/dymensionxyz/dymint/store" "github.com/dymensionxyz/dymint/types" "github.com/tendermint/tendermint/libs/pubsub" @@ -17,7 +16,7 @@ import ( // DataAvailabilityLayerClient is intended only for usage in tests. // It does actually ensures DA - it stores data in-memory. type DataAvailabilityLayerClient struct { - logger log.Logger + logger types.Logger dalcKV store.KVStore daHeight uint64 config config @@ -33,7 +32,7 @@ var _ da.DataAvailabilityLayerClient = &DataAvailabilityLayerClient{} var _ da.BatchRetriever = &DataAvailabilityLayerClient{} // Init is called once to allow DA client to read configuration and initialize resources. -func (m *DataAvailabilityLayerClient) Init(config []byte, _ *pubsub.Server, dalcKV store.KVStore, logger log.Logger, options ...da.Option) error { +func (m *DataAvailabilityLayerClient) Init(config []byte, _ *pubsub.Server, dalcKV store.KVStore, logger types.Logger, options ...da.Option) error { m.logger = logger m.dalcKV = dalcKV m.daHeight = 1 diff --git a/mocks/settlement/settlement_layer.go b/mocks/settlement/settlement_layer.go index 1a789e023..a6e39e0b0 100644 --- a/mocks/settlement/settlement_layer.go +++ b/mocks/settlement/settlement_layer.go @@ -4,7 +4,7 @@ package mocks import ( da "github.com/dymensionxyz/dymint/da" - log "github.com/dymensionxyz/dymint/log" + log "github.com/dymensionxyz/dymint/types" mock "github.com/stretchr/testify/mock" diff --git a/p2p/client.go b/p2p/client.go index 042bdc617..04e1891be 100644 --- a/p2p/client.go +++ b/p2p/client.go @@ -23,7 +23,7 @@ import ( "go.uber.org/multierr" "github.com/dymensionxyz/dymint/config" - "github.com/dymensionxyz/dymint/log" + "github.com/dymensionxyz/dymint/types" ) // TODO(tzdybal): refactor to configuration parameters @@ -71,14 +71,14 @@ type Client struct { // it's required because of discovery.Advertise call cancel context.CancelFunc - logger log.Logger + logger types.Logger } // NewClient creates new Client object. // // Basic checks on parameters are done, and default parameters are provided for unset-configuration // TODO(tzdybal): consider passing entire config, not just P2P config, to reduce number of arguments -func NewClient(conf config.P2PConfig, privKey crypto.PrivKey, chainID string, logger log.Logger) (*Client, error) { +func NewClient(conf config.P2PConfig, privKey crypto.PrivKey, chainID string, logger types.Logger) (*Client, error) { if privKey == nil { return nil, errNoPrivKey } diff --git a/p2p/client_test.go b/p2p/client_test.go index 739aea83d..a486d5536 100644 --- a/p2p/client_test.go +++ b/p2p/client_test.go @@ -16,7 +16,7 @@ import ( "github.com/tendermint/tendermint/libs/log" "github.com/dymensionxyz/dymint/config" - "github.com/dymensionxyz/dymint/log/test" + "github.com/dymensionxyz/dymint/testutil" ) func TestClientStartup(t *testing.T) { @@ -166,7 +166,7 @@ func TestSeedStringParsing(t *testing.T) { t.Run(c.name, func(t *testing.T) { assert := assert.New(t) require := require.New(t) - logger := &test.MockLogger{} + logger := &testutil.MockLogger{} client, err := NewClient(config.P2PConfig{ GossipCacheSize: 50, BoostrapTime: 30 * time.Second}, privKey, "TestNetwork", logger) diff --git a/p2p/gossip.go b/p2p/gossip.go index 84a18a9ec..16de820d1 100644 --- a/p2p/gossip.go +++ b/p2p/gossip.go @@ -9,7 +9,7 @@ import ( "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/peer" - "github.com/dymensionxyz/dymint/log" + "github.com/dymensionxyz/dymint/types" ) // GossipMessage represents message gossiped via P2P network (e.g. transaction, Block etc). @@ -36,13 +36,13 @@ type Gossiper struct { topic *pubsub.Topic sub *pubsub.Subscription - logger log.Logger + logger types.Logger } // NewGossiper creates new, ready to use instance of Gossiper. // // Returned Gossiper object can be used for sending (Publishing) and receiving messages in topic identified by topicStr. -func NewGossiper(host host.Host, ps *pubsub.PubSub, topicStr string, logger log.Logger, options ...GossiperOption) (*Gossiper, error) { +func NewGossiper(host host.Host, ps *pubsub.PubSub, topicStr string, logger types.Logger, options ...GossiperOption) (*Gossiper, error) { topic, err := ps.Join(topicStr) if err != nil { return nil, err diff --git a/p2p/utils_test.go b/p2p/utils_test.go index b9c6e7322..ade6347f4 100644 --- a/p2p/utils_test.go +++ b/p2p/utils_test.go @@ -17,7 +17,7 @@ import ( "go.uber.org/multierr" "github.com/dymensionxyz/dymint/config" - "github.com/dymensionxyz/dymint/log" + "github.com/dymensionxyz/dymint/types" ) type testNet []*Client @@ -63,7 +63,7 @@ func getAddr(sk crypto.PrivKey) (multiaddr.Multiaddr, error) { return a, nil } -func startTestNetwork(ctx context.Context, t *testing.T, n int, conf map[int]hostDescr, validators []GossipValidator, logger log.Logger) testNet { +func startTestNetwork(ctx context.Context, t *testing.T, n int, conf map[int]hostDescr, validators []GossipValidator, logger types.Logger) testNet { t.Helper() require := require.New(t) diff --git a/p2p/validator.go b/p2p/validator.go index 43f542ff1..95483d3ae 100644 --- a/p2p/validator.go +++ b/p2p/validator.go @@ -4,9 +4,9 @@ import ( "context" "errors" - "github.com/dymensionxyz/dymint/log" "github.com/dymensionxyz/dymint/mempool" nodemempool "github.com/dymensionxyz/dymint/node/mempool" + "github.com/dymensionxyz/dymint/types" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/pubsub" corep2p "github.com/tendermint/tendermint/p2p" @@ -24,14 +24,14 @@ type IValidator interface { // Validator is a validator for messages gossiped in the p2p network. type Validator struct { - logger log.Logger + logger types.Logger localPubsubServer *pubsub.Server } var _ IValidator = (*Validator)(nil) // NewValidator creates a new Validator. -func NewValidator(logger log.Logger, pusbsubServer *pubsub.Server) *Validator { +func NewValidator(logger types.Logger, pusbsubServer *pubsub.Server) *Validator { return &Validator{ logger: logger, localPubsubServer: pusbsubServer, diff --git a/rpc/json/handler.go b/rpc/json/handler.go index 955b96403..69f104b04 100644 --- a/rpc/json/handler.go +++ b/rpc/json/handler.go @@ -13,7 +13,7 @@ import ( tmjson "github.com/tendermint/tendermint/libs/json" - "github.com/dymensionxyz/dymint/log" + "github.com/dymensionxyz/dymint/types" "github.com/gorilla/rpc/v2" "github.com/gorilla/rpc/v2/json2" ) @@ -22,10 +22,10 @@ type handler struct { srv *service mux *http.ServeMux codec rpc.Codec - logger log.Logger + logger types.Logger } -func newHandler(s *service, codec rpc.Codec, logger log.Logger) *handler { +func newHandler(s *service, codec rpc.Codec, logger types.Logger) *handler { mux := http.NewServeMux() h := &handler{ srv: s, diff --git a/rpc/json/service.go b/rpc/json/service.go index 2ca67b739..42ff81bd0 100644 --- a/rpc/json/service.go +++ b/rpc/json/service.go @@ -17,12 +17,12 @@ import ( ctypes "github.com/tendermint/tendermint/rpc/core/types" rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types" - "github.com/dymensionxyz/dymint/log" "github.com/dymensionxyz/dymint/rpc/client" + "github.com/dymensionxyz/dymint/types" ) // GetHTTPHandler returns handler configured to serve Tendermint-compatible RPC. -func GetHTTPHandler(l *client.Client, logger log.Logger) (http.Handler, error) { +func GetHTTPHandler(l *client.Client, logger types.Logger) (http.Handler, error) { return newHandler(newService(l, logger), json2.NewCodec(), logger), nil } @@ -47,10 +47,10 @@ func newMethod(m interface{}) *method { type service struct { client *client.Client methods map[string]*method - logger log.Logger + logger types.Logger } -func newService(c *client.Client, l log.Logger) *service { +func newService(c *client.Client, l types.Logger) *service { s := service{ client: c, logger: l, diff --git a/rpc/json/ws.go b/rpc/json/ws.go index 84139c8a4..e5210fe5d 100644 --- a/rpc/json/ws.go +++ b/rpc/json/ws.go @@ -8,14 +8,14 @@ import ( "github.com/gorilla/websocket" - "github.com/dymensionxyz/dymint/log" + "github.com/dymensionxyz/dymint/types" tmpubsub "github.com/tendermint/tendermint/libs/pubsub" ) type wsConn struct { conn *websocket.Conn queue chan []byte - logger log.Logger + logger types.Logger } func (wsc *wsConn) sendLoop() { diff --git a/settlement/base.go b/settlement/base.go index 93f3a697b..2f55c63ae 100644 --- a/settlement/base.go +++ b/settlement/base.go @@ -5,14 +5,13 @@ import ( "fmt" "github.com/dymensionxyz/dymint/da" - "github.com/dymensionxyz/dymint/log" "github.com/dymensionxyz/dymint/types" "github.com/tendermint/tendermint/libs/pubsub" ) // BaseLayerClient is intended only for usage in tests. type BaseLayerClient struct { - logger log.Logger + logger types.Logger pubsub *pubsub.Server sequencersList []*types.Sequencer config Config @@ -31,7 +30,7 @@ func WithHubClient(hubClient HubClient) Option { } // Init is called once. it initializes the struct members. -func (b *BaseLayerClient) Init(config Config, pubsub *pubsub.Server, logger log.Logger, options ...Option) error { +func (b *BaseLayerClient) Init(config Config, pubsub *pubsub.Server, logger types.Logger, options ...Option) error { var err error b.config = config b.pubsub = pubsub diff --git a/settlement/dymension/dymension.go b/settlement/dymension/dymension.go index 4e8ec7d43..6ba698766 100644 --- a/settlement/dymension/dymension.go +++ b/settlement/dymension/dymension.go @@ -22,7 +22,6 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sequencertypes "github.com/dymensionxyz/dymension/v3/x/sequencer/types" "github.com/dymensionxyz/dymint/da" - "github.com/dymensionxyz/dymint/log" "github.com/dymensionxyz/dymint/settlement" "github.com/dymensionxyz/dymint/types" "github.com/dymensionxyz/dymint/utils" @@ -61,7 +60,7 @@ type LayerClient struct { var _ settlement.LayerI = &LayerClient{} // Init is called once. it initializes the struct members. -func (dlc *LayerClient) Init(config settlement.Config, pubsub *pubsub.Server, logger log.Logger, options ...settlement.Option) error { +func (dlc *LayerClient) Init(config settlement.Config, pubsub *pubsub.Server, logger types.Logger, options ...settlement.Option) error { DymensionCosmosClient, err := newDymensionHubClient(config, pubsub, logger) if err != nil { return err @@ -85,7 +84,7 @@ func (dlc *LayerClient) Init(config settlement.Config, pubsub *pubsub.Server, lo // HubClient is the client for the Dymension Hub. type HubClient struct { config *settlement.Config - logger log.Logger + logger types.Logger pubsub *pubsub.Server client CosmosClient ctx context.Context @@ -135,7 +134,7 @@ func WithBatchRetryDelay(batchRetryDelay time.Duration) Option { } } -func newDymensionHubClient(config settlement.Config, pubsub *pubsub.Server, logger log.Logger, options ...Option) (*HubClient, error) { +func newDymensionHubClient(config settlement.Config, pubsub *pubsub.Server, logger types.Logger, options ...Option) (*HubClient, error) { ctx, cancel := context.WithCancel(context.Background()) eventMap := map[string]string{ fmt.Sprintf(eventStateUpdate, config.RollappID): settlement.EventNewSettlementBatchAccepted, diff --git a/settlement/grpc/grpc.go b/settlement/grpc/grpc.go index d379d003c..20f70a28a 100644 --- a/settlement/grpc/grpc.go +++ b/settlement/grpc/grpc.go @@ -20,7 +20,6 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" rollapptypes "github.com/dymensionxyz/dymension/v3/x/rollapp/types" "github.com/dymensionxyz/dymint/da" - "github.com/dymensionxyz/dymint/log" "github.com/dymensionxyz/dymint/settlement" "github.com/dymensionxyz/dymint/types" @@ -38,7 +37,7 @@ type LayerClient struct { var _ settlement.LayerI = (*LayerClient)(nil) // Init initializes the mock layer client. -func (m *LayerClient) Init(config settlement.Config, pubsub *pubsub.Server, logger log.Logger, options ...settlement.Option) error { +func (m *LayerClient) Init(config settlement.Config, pubsub *pubsub.Server, logger types.Logger, options ...settlement.Option) error { HubClientMock, err := newHubClient(config, pubsub, logger) if err != nil { return err @@ -64,7 +63,7 @@ type HubGrpcClient struct { ctx context.Context ProposerPubKey string slStateIndex uint64 - logger log.Logger + logger types.Logger pubsub *pubsub.Server latestHeight uint64 conn *grpc.ClientConn @@ -75,7 +74,7 @@ type HubGrpcClient struct { var _ settlement.HubClient = &HubGrpcClient{} -func newHubClient(config settlement.Config, pubsub *pubsub.Server, logger log.Logger) (*HubGrpcClient, error) { +func newHubClient(config settlement.Config, pubsub *pubsub.Server, logger types.Logger) (*HubGrpcClient, error) { ctx := context.Background() latestHeight := uint64(0) diff --git a/settlement/local/local.go b/settlement/local/local.go index 18978958e..45cb541cf 100644 --- a/settlement/local/local.go +++ b/settlement/local/local.go @@ -18,7 +18,6 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" rollapptypes "github.com/dymensionxyz/dymension/v3/x/rollapp/types" "github.com/dymensionxyz/dymint/da" - "github.com/dymensionxyz/dymint/log" "github.com/dymensionxyz/dymint/settlement" "github.com/dymensionxyz/dymint/store" "github.com/dymensionxyz/dymint/types" @@ -42,7 +41,7 @@ type LayerClient struct { var _ settlement.LayerI = (*LayerClient)(nil) // Init initializes the mock layer client. -func (m *LayerClient) Init(config settlement.Config, pubsub *pubsub.Server, logger log.Logger, options ...settlement.Option) error { +func (m *LayerClient) Init(config settlement.Config, pubsub *pubsub.Server, logger types.Logger, options ...settlement.Option) error { HubClientMock, err := newHubClient(config, pubsub, logger) if err != nil { return err @@ -67,7 +66,7 @@ func (m *LayerClient) Init(config settlement.Config, pubsub *pubsub.Server, logg type HubClient struct { ProposerPubKey string slStateIndex uint64 - logger log.Logger + logger types.Logger pubsub *pubsub.Server latestHeight uint64 settlementKV store.KVStore @@ -75,7 +74,7 @@ type HubClient struct { var _ settlement.HubClient = &HubClient{} -func newHubClient(config settlement.Config, pubsub *pubsub.Server, logger log.Logger) (*HubClient, error) { +func newHubClient(config settlement.Config, pubsub *pubsub.Server, logger types.Logger) (*HubClient, error) { latestHeight := uint64(0) slStateIndex := uint64(0) slstore, proposer, err := initConfig(config) diff --git a/settlement/settlement.go b/settlement/settlement.go index a873297af..406342dd1 100644 --- a/settlement/settlement.go +++ b/settlement/settlement.go @@ -2,7 +2,6 @@ package settlement import ( "github.com/dymensionxyz/dymint/da" - "github.com/dymensionxyz/dymint/log" "github.com/dymensionxyz/dymint/types" "github.com/tendermint/tendermint/libs/pubsub" ) @@ -56,7 +55,7 @@ type Option func(LayerI) type LayerI interface { // Init is called once for the client initialization - Init(config Config, pubsub *pubsub.Server, logger log.Logger, options ...Option) error + Init(config Config, pubsub *pubsub.Server, logger types.Logger, options ...Option) error // Start is called once, after Init. It's implementation should start the client service. Start() error diff --git a/state/executor.go b/state/executor.go index 886ef4431..cecfa4416 100644 --- a/state/executor.go +++ b/state/executor.go @@ -18,7 +18,6 @@ import ( "go.uber.org/multierr" abciconv "github.com/dymensionxyz/dymint/conv/abci" - "github.com/dymensionxyz/dymint/log" "github.com/dymensionxyz/dymint/mempool" "github.com/dymensionxyz/dymint/types" ) @@ -34,12 +33,12 @@ type BlockExecutor struct { eventBus *tmtypes.EventBus - logger log.Logger + logger types.Logger } // NewBlockExecutor creates new instance of BlockExecutor. // Proposer address and namespace ID will be used in all newly created blocks. -func NewBlockExecutor(proposerAddress []byte, namespaceID string, chainID string, mempool mempool.Mempool, proxyApp proxy.AppConns, eventBus *tmtypes.EventBus, logger log.Logger) (*BlockExecutor, error) { +func NewBlockExecutor(proposerAddress []byte, namespaceID string, chainID string, mempool mempool.Mempool, proxyApp proxy.AppConns, eventBus *tmtypes.EventBus, logger types.Logger) (*BlockExecutor, error) { bytes, err := hex.DecodeString(namespaceID) if err != nil { return nil, err diff --git a/log/test/loggers.go b/testutil/logger.go similarity index 99% rename from log/test/loggers.go rename to testutil/logger.go index e855a4183..3ef7a902d 100644 --- a/log/test/loggers.go +++ b/testutil/logger.go @@ -1,4 +1,4 @@ -package test +package testutil import ( "fmt" diff --git a/log/logger.go b/types/logger.go similarity index 93% rename from log/logger.go rename to types/logger.go index 0f765f841..e2c8fcdac 100644 --- a/log/logger.go +++ b/types/logger.go @@ -1,4 +1,4 @@ -package log +package types // Logger interface is compatible with Tendermint logger type Logger interface { diff --git a/utils/events.go b/utils/events.go index 89a053173..537a305e9 100644 --- a/utils/events.go +++ b/utils/events.go @@ -3,12 +3,12 @@ package utils import ( "context" - "github.com/dymensionxyz/dymint/log" + "github.com/dymensionxyz/dymint/types" "github.com/tendermint/tendermint/libs/pubsub" ) // SubscribeAndHandleEvents subscribes to events and sends back a callback -func SubscribeAndHandleEvents(ctx context.Context, pubsubServer *pubsub.Server, clientID string, eventQuery pubsub.Query, callback func(event pubsub.Message), logger log.Logger, outCapacity ...int) { +func SubscribeAndHandleEvents(ctx context.Context, pubsubServer *pubsub.Server, clientID string, eventQuery pubsub.Query, callback func(event pubsub.Message), logger types.Logger, outCapacity ...int) { subscription, err := pubsubServer.Subscribe(ctx, clientID, eventQuery, outCapacity...) if err != nil { logger.Error("failed to subscribe to events")