diff --git a/astria/execution/handler.go b/astria/execution/handler.go index d8edf084d..1d581b075 100644 --- a/astria/execution/handler.go +++ b/astria/execution/handler.go @@ -5,7 +5,7 @@ import ( "net" "sync" - astriaGrpc "buf.build/gen/go/astria/astria/grpc/go/astria/execution/v1alpha2/executionv1alpha2grpc" + astriaGrpc "buf.build/gen/go/astria/execution-apis/grpc/go/astria/execution/v1alpha2/executionv1alpha2grpc" "google.golang.org/grpc" ) diff --git a/astria/execution/v1alpha2.go b/astria/execution/v1alpha2.go index 0548df679..acad29966 100644 --- a/astria/execution/v1alpha2.go +++ b/astria/execution/v1alpha2.go @@ -3,9 +3,10 @@ package execution import ( "context" "sync" + "time" - astriaGrpc "buf.build/gen/go/astria/astria/grpc/go/astria/execution/v1alpha2/executionv1alpha2grpc" - astriaPb "buf.build/gen/go/astria/astria/protocolbuffers/go/astria/execution/v1alpha2" + astriaGrpc "buf.build/gen/go/astria/execution-apis/grpc/go/astria/execution/v1alpha2/executionv1alpha2grpc" + astriaPb "buf.build/gen/go/astria/execution-apis/protocolbuffers/go/astria/execution/v1alpha2" cmbytes "github.com/cometbft/cometbft/libs/bytes" "github.com/cometbft/cometbft/libs/log" "github.com/rollkit/rollkit/block" @@ -13,6 +14,7 @@ import ( "github.com/rollkit/rollkit/types" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" + "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/types/known/timestamppb" ) @@ -37,7 +39,8 @@ func NewExecutionServiceServerV1Alpha2(blockManager *block.SSManager, store stor // GetBlock retrieves a block by its identifier. func (s *ExecutionServiceServerV1Alpha2) GetBlock(ctx context.Context, req *astriaPb.GetBlockRequest) (*astriaPb.Block, error) { - s.logger.Info("GetBlock called", "request", req) + reqJson, _ := protojson.Marshal(req) + s.logger.Info("GetBlock called", "request", reqJson) res, err := s.getBlockFromIdentifier(ctx, req.GetIdentifier()) if err != nil { @@ -45,13 +48,16 @@ func (s *ExecutionServiceServerV1Alpha2) GetBlock(ctx context.Context, req *astr return nil, err } - s.logger.Info("GetBlock completed", "request", req, "response", res) + resJson, _ := protojson.Marshal(res) + s.logger.Info("GetBlock completed", "response", resJson) return res, nil } // BatchGetBlocks will return an array of Blocks given an array of block identifiers. func (s *ExecutionServiceServerV1Alpha2) BatchGetBlocks(ctx context.Context, req *astriaPb.BatchGetBlocksRequest) (*astriaPb.BatchGetBlocksResponse, error) { - s.logger.Info("BatchGetBlocks called", "request", req) + reqJson, _ := protojson.Marshal(req) + s.logger.Info("BatchGetBlocks called", "request", reqJson) + var blocks []*astriaPb.Block ids := req.GetIdentifiers() @@ -69,7 +75,8 @@ func (s *ExecutionServiceServerV1Alpha2) BatchGetBlocks(ctx context.Context, req Blocks: blocks, } - s.logger.Info("BatchGetBlocks completed", "request", req, "response", res) + resJson, _ := protojson.Marshal(res) + s.logger.Info("BatchGetBlocks completed", "response", resJson) return res, nil } @@ -81,7 +88,8 @@ func (s *ExecutionServiceServerV1Alpha2) ExecuteBlock(ctx context.Context, req * default: } - s.logger.Info("ExecuteBlock called", "request", req) + reqJson, _ := protojson.Marshal(req) + s.logger.Info("ExecuteBlock called", "request", reqJson) s.blockExecutionLock.Lock() defer s.blockExecutionLock.Unlock() @@ -93,31 +101,81 @@ func (s *ExecutionServiceServerV1Alpha2) ExecuteBlock(ctx context.Context, req * block, err := s.blockManager.PublishBlock(ctx, types.Hash(req.PrevBlockHash), req.Timestamp.AsTime(), txs) if err != nil { - s.logger.Error("failed to publish block to chain", "hash", block.Hash(), "prevHash", req.PrevBlockHash, "err", err) + s.logger.Error("Failed to publish block to chain", "hash", block.Hash(), "prevHash", types.Hash(req.PrevBlockHash), "err", err) return nil, status.Error(codes.Internal, "failed to insert block to chain") } + s.logger.Info("Published block", "height", block.Height(), "timestamp", block.Time(), "hash", block.Hash(), "parent_hash", block.LastHeader()) + + parentHash := block.LastHeader() + if block.Height() == 1 { + zeroHash := [32]byte{0x0} + parentHash = types.Hash(zeroHash[:]) + } + res := &astriaPb.Block{ Number: uint32(block.Height()), Hash: cmbytes.HexBytes(block.Hash()), - ParentBlockHash: cmbytes.HexBytes(block.LastHeader()), + ParentBlockHash: cmbytes.HexBytes(parentHash), Timestamp: timestamppb.New(block.Time()), } - s.logger.Info("ExecuteBlock completed", "request", req, "response", res) + resJson, _ := protojson.Marshal(res) + s.logger.Info("ExecuteBlock completed", "response", resJson) return res, nil } // GetCommitmentState fetches the current CommitmentState of the chain. func (s *ExecutionServiceServerV1Alpha2) GetCommitmentState(ctx context.Context, req *astriaPb.GetCommitmentStateRequest) (*astriaPb.CommitmentState, error) { - s.logger.Info("GetCommitmentState called", "request", req) - return nil, nil + reqJson, _ := protojson.Marshal(req) + s.logger.Info("GetCommitmentState called", "request", reqJson) + + var res *astriaPb.CommitmentState + + height := s.blockManager.GetStoreHeight() + + if height == 0 { + genHash := [32]byte{0x0} + pbGenBlock := &astriaPb.Block{ + Number: uint32(0), + Hash: genHash[:], + ParentBlockHash: genHash[:], + Timestamp: timestamppb.New(time.Now()), + } + res = &astriaPb.CommitmentState{ + Soft: pbGenBlock, + Firm: pbGenBlock, + } + } else { + block, err := s.store.GetBlock(ctx, height) + if err != nil { + s.logger.Error("failed finding block with height", "height", height, "error", err) + return nil, err + } + + pbBlock := &astriaPb.Block{ + Number: uint32(block.Height()), + Hash: cmbytes.HexBytes(block.Hash()), + ParentBlockHash: cmbytes.HexBytes(block.LastHeader()), + Timestamp: timestamppb.New(block.Time()), + } + + res = &astriaPb.CommitmentState{ + Soft: pbBlock, + Firm: pbBlock, + } + } + + resJson, _ := protojson.Marshal(res) + s.logger.Info("GetCommitmentState completed", "response", resJson) + return res, nil } // UpdateCommitmentState replaces the whole CommitmentState with a new CommitmentState. func (s *ExecutionServiceServerV1Alpha2) UpdateCommitmentState(ctx context.Context, req *astriaPb.UpdateCommitmentStateRequest) (*astriaPb.CommitmentState, error) { - s.logger.Info("UpdateCommitmentState called", "request", req) - return nil, nil + reqJson, _ := protojson.Marshal(req) + s.logger.Info("UpdateCommitmentState called", "request", reqJson) + return req.CommitmentState, nil } func (s *ExecutionServiceServerV1Alpha2) getBlockFromIdentifier(ctx context.Context, identifier *astriaPb.BlockIdentifier) (*astriaPb.Block, error) { diff --git a/astria/mempool/reaper.go b/astria/mempool/reaper.go index 3ef46cb69..669665f0d 100644 --- a/astria/mempool/reaper.go +++ b/astria/mempool/reaper.go @@ -4,25 +4,26 @@ import ( "fmt" "sync" - "github.com/rollkit/rollkit/mempool" - "github.com/rollkit/rollkit/types" - + "github.com/cometbft/cometbft/libs/log" "github.com/rollkit/rollkit/astria/sequencer" + "github.com/rollkit/rollkit/mempool" ) type MempoolReaper struct { c *sequencer.Client mempool *mempool.CListMempool + logger log.Logger mu sync.Mutex started bool stopCh chan struct{} } -func NewMempoolReaper(client *sequencer.Client, mempool *mempool.CListMempool) *MempoolReaper { +func NewMempoolReaper(client *sequencer.Client, mempool *mempool.CListMempool, logger log.Logger) *MempoolReaper { return &MempoolReaper{ c: client, mempool: mempool, + logger: logger, started: false, stopCh: make(chan struct{}), } @@ -47,10 +48,12 @@ func (mr *MempoolReaper) Reap() { case <-mr.stopCh: return default: - mempoolTx := tx0.Value.(*mempoolTx) + mempoolTx := tx0.Value.(*mempool.MempoolTx) + + mr.logger.Info("reaped tx from mempool", "tx", mempoolTx.Tx()) // submit to shared sequencer - res, err := mr.c.BroadcastTx(mempoolTx.tx) + res, err := mr.c.BroadcastTx(mempoolTx.Tx()) if err != nil { panic(fmt.Sprintf("error sending message: %s\n", err)) } @@ -95,17 +98,3 @@ func (mr *MempoolReaper) Stop() error { mr.started = false return nil } - -// copied from rollkit clist_mempool.go -//-------------------------------------------------------------------------------- - -// mempoolTx is a transaction that successfully ran -type mempoolTx struct { - height uint64 // height that this tx had been validated in - gasWanted int64 // amount of gas this tx states it will require - tx types.Tx // - - // ids of peers who've sent us this tx (as a map for quick lookups). - // senders: PeerID -> bool - senders sync.Map -} diff --git a/astria/sequencer/client.go b/astria/sequencer/client.go index a9c9f060d..de139f9d5 100644 --- a/astria/sequencer/client.go +++ b/astria/sequencer/client.go @@ -8,6 +8,7 @@ import ( astriaPb "buf.build/gen/go/astria/astria/protocolbuffers/go/astria/sequencer/v1alpha1" "github.com/astriaorg/go-sequencer-client/client" tendermintPb "github.com/cometbft/cometbft/rpc/core/types" + "google.golang.org/protobuf/encoding/protojson" ) // SequencerClient is a client for interacting with the sequencer. @@ -51,7 +52,8 @@ func (c *Client) BroadcastTx(tx []byte) (*tendermintPb.ResultBroadcastTx, error) return nil, err } - fmt.Printf("submitting tx to sequencer: %s\n", tx) + signedJson, _ := protojson.Marshal(signed) + fmt.Printf("submitting tx to sequencer: %s\n", signedJson) resp, err := c.Client.BroadcastTxSync(context.Background(), signed) if err != nil { diff --git a/block/ss_manager.go b/block/ss_manager.go index f5a2fd74a..e2af0a2cb 100644 --- a/block/ss_manager.go +++ b/block/ss_manager.go @@ -68,6 +68,7 @@ func NewSSManager( exec := state.NewBlockExecutor(proposerAddress, genesis.ChainID, mempool, proxyApp, eventBus, logger, execMetrics) if s.LastBlockHeight+1 == uint64(genesis.InitialHeight) { + logger.Info("Initializing chain") res, err := exec.InitChain(genesis) if err != nil { return nil, err diff --git a/config/defaults.go b/config/defaults.go index 3c33d6861..eed63987f 100644 --- a/config/defaults.go +++ b/config/defaults.go @@ -11,7 +11,7 @@ const ( DefaultListenAddress = "/ip4/0.0.0.0/tcp/7676" // Version is the current rollkit version // Please keep updated with each new release - Version = "0.12.0" + Version = "0.13.0" ) // DefaultNodeConfig keeps default values of NodeConfig diff --git a/go.mod b/go.mod index 8a239ab18..ac1457635 100644 --- a/go.mod +++ b/go.mod @@ -33,19 +33,15 @@ require ( ) require ( + buf.build/gen/go/astria/astria/protocolbuffers/go v1.32.0-20240208041217-cec081a8099b.1 + buf.build/gen/go/astria/execution-apis/grpc/go v1.3.0-20240207231045-2f6384a93a8d.2 + buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.32.0-20240207231045-2f6384a93a8d.1 + github.com/astriaorg/go-sequencer-client v0.0.0-20231201013457-0df599de8e74 github.com/celestiaorg/go-header v0.5.2 github.com/ipfs/go-ds-badger4 v0.1.5 ) require ( - buf.build/gen/go/astria/astria/grpc/go v1.3.0-20240207143250-56389ebbf26d.2 // indirect - buf.build/gen/go/astria/astria/protocolbuffers/go v1.31.0-20231130012811-2fd7e6d46ebd.2 // indirect - buf.build/gen/go/cosmos/cosmos-proto/protocolbuffers/go v1.31.0-20211202220400-1935555c206d.2 // indirect - buf.build/gen/go/cosmos/cosmos-sdk/protocolbuffers/go v1.31.0-20230719110346-aa25660f4ff7.2 // indirect - buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.31.0-20230509103710-5e5b9fdd0180.2 // indirect - buf.build/gen/go/cosmos/ibc/protocolbuffers/go v1.31.0-20230913112312-7ab44ae956a0.2 // indirect - buf.build/gen/go/penumbra-zone/penumbra/protocolbuffers/go v1.31.0-20231120132728-bc443669626d.2 // indirect - github.com/astriaorg/go-sequencer-client v0.0.0-20231201013457-0df599de8e74 // indirect github.com/benbjohnson/clock v1.3.5 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect @@ -184,8 +180,6 @@ require ( golang.org/x/text v0.14.0 // indirect golang.org/x/tools v0.16.0 // indirect gonum.org/v1/gonum v0.12.0 // indirect - google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index b14534fb3..ccabab72b 100644 --- a/go.sum +++ b/go.sum @@ -1,39 +1,20 @@ 4d63.com/gochecknoglobals v0.1.0/go.mod h1:wfdC5ZjKSPr7CybKEcgJhUOgeAQW1+7WcyK8OvUilfo= bitbucket.org/creachadair/shell v0.0.6/go.mod h1:8Qqi/cYk7vPnsOePHroKXDJYmb5x7ENhtiFtfZq8K+M= -buf.build/gen/go/astria/astria/grpc/go v1.3.0-20240207143250-56389ebbf26d.2 h1:TjK8mVSKiEjRGqlGY6wZxRQ5HbCIYdMBsK2Zd9nDhLE= -buf.build/gen/go/astria/astria/grpc/go v1.3.0-20240207143250-56389ebbf26d.2/go.mod h1:SlvP7PtR9LgD3ztU6fSYforRZ0CNpw7G4BREXgWlLOc= -buf.build/gen/go/astria/astria/protocolbuffers/go v1.28.1-20240207143250-56389ebbf26d.4/go.mod h1:a2nDGgMECtFWAbBm06prW70xA/jP8X44wz9jpii2cxo= -buf.build/gen/go/astria/astria/protocolbuffers/go v1.31.0-20231130012811-2fd7e6d46ebd.2 h1:gq4dRHG9GJEh8tkTsFwgrHA+tPiZead6YKRgsaidQJg= -buf.build/gen/go/astria/astria/protocolbuffers/go v1.31.0-20231130012811-2fd7e6d46ebd.2/go.mod h1:OPKBvxqrsHTBen+bbkQT/beHK/aSznSulzR+JeDSUKw= -buf.build/gen/go/cosmos/cosmos-proto/grpc/go v1.3.0-20211202220400-1935555c206d.2/go.mod h1:AS+jUupCTrSz+T88+ZsW4cOQwkYftIjjMzqXoK0hp3k= -buf.build/gen/go/cosmos/cosmos-proto/protocolbuffers/go v1.28.1-20211202220400-1935555c206d.4/go.mod h1:eLpHyQeVRAtShjbHVpIla0w/42RZAdaaTpBErMv/6sc= -buf.build/gen/go/cosmos/cosmos-proto/protocolbuffers/go v1.31.0-20211202220400-1935555c206d.2 h1:O+V9Yq7KkauH1cMnUAHxsl5n+b7ZD/RZnHo9ZiJICGg= -buf.build/gen/go/cosmos/cosmos-proto/protocolbuffers/go v1.31.0-20211202220400-1935555c206d.2/go.mod h1:yHKMbegvhfMbDGsQp/q7tECJTfZf0wrgTRcH1glgEQk= -buf.build/gen/go/cosmos/cosmos-sdk/grpc/go v1.3.0-20230522115704-e7a85cef453e.2/go.mod h1:cZOEXwhGC2HYgN4DJvbdZNEWGnghUlN7ZwkyJKKqw/g= -buf.build/gen/go/cosmos/cosmos-sdk/grpc/go v1.3.0-20230719110346-aa25660f4ff7.2/go.mod h1:u82E8x7rLqs3igb0i4Ul1fFwx384I7oJnmn4FmclOTw= -buf.build/gen/go/cosmos/cosmos-sdk/protocolbuffers/go v1.28.1-20230522115704-e7a85cef453e.4/go.mod h1:WwWRz97saFM8fwl9UcqhFzQOvN+8QkZwa4AAL37pqaA= -buf.build/gen/go/cosmos/cosmos-sdk/protocolbuffers/go v1.28.1-20230719110346-aa25660f4ff7.4/go.mod h1:RFHPh4mUMobZH69MX2BCwzRVG+JNUfAp9J2fIiYylcA= -buf.build/gen/go/cosmos/cosmos-sdk/protocolbuffers/go v1.31.0-20230522115704-e7a85cef453e.2/go.mod h1:d16Ahcn3H831Oe+NnNOWuXkV3aTiPOBZvUAZaHYECkU= -buf.build/gen/go/cosmos/cosmos-sdk/protocolbuffers/go v1.31.0-20230719110346-aa25660f4ff7.2 h1:mDJdIdbHw10arzuVIpFoQr6h8cxKPcdT2r91Q2izQu0= -buf.build/gen/go/cosmos/cosmos-sdk/protocolbuffers/go v1.31.0-20230719110346-aa25660f4ff7.2/go.mod h1:vg3BLbBJ3Vl9Wu7GE6BmxYq1+VMU4Yg8cv9YG7qF2AQ= -buf.build/gen/go/cosmos/gogo-proto/grpc/go v1.3.0-20221020125208-34d970b699f8.2/go.mod h1:PKPJRNiORF0FABGYEXbc1iTG+rzNA/4JUfDGkaFPskA= -buf.build/gen/go/cosmos/gogo-proto/grpc/go v1.3.0-20230509103710-5e5b9fdd0180.2/go.mod h1:VLlOf39tq7bgN9oEwG9ElFuzSHlDRrlp6be0GQW9oCw= -buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.28.1-20221020125208-34d970b699f8.4/go.mod h1:yABYnsmLNsRsuOb4SD5Xr511HUTzjhrc5KD1nFHIiNs= -buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.28.1-20230509103710-5e5b9fdd0180.4/go.mod h1:yABYnsmLNsRsuOb4SD5Xr511HUTzjhrc5KD1nFHIiNs= -buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.31.0-20221020125208-34d970b699f8.2/go.mod h1:rTzewyj2LANV2IIuGZnKMsvbIEVAguDwBvMdxD1pa3k= -buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.31.0-20230509103710-5e5b9fdd0180.2 h1:4JCzFq6Gwr5hx3BpGky420OsrZjdMI8rAB3T7zcsDrs= -buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.31.0-20230509103710-5e5b9fdd0180.2/go.mod h1:rTzewyj2LANV2IIuGZnKMsvbIEVAguDwBvMdxD1pa3k= -buf.build/gen/go/cosmos/ibc/grpc/go v1.3.0-20230913112312-7ab44ae956a0.2/go.mod h1:BO30VkuVfhMtQHD6CSpVR2Q646XCJuwlrTp/OkgJxYg= -buf.build/gen/go/cosmos/ibc/protocolbuffers/go v1.28.1-20230913112312-7ab44ae956a0.4/go.mod h1:0kwZox/T/DuD4YiSHSn76mEPEFraCnaWwdkuhHrcr/s= -buf.build/gen/go/cosmos/ibc/protocolbuffers/go v1.31.0-20230913112312-7ab44ae956a0.2 h1:9LwQA/UwYerRClC/fNzeyynz+AfDenAmyZj5G8HPLmU= -buf.build/gen/go/cosmos/ibc/protocolbuffers/go v1.31.0-20230913112312-7ab44ae956a0.2/go.mod h1:piKWSxT4f990Ium90hWQnNwuqxhsoYxhPtZYcOz2vNs= -buf.build/gen/go/cosmos/ics23/grpc/go v1.3.0-20221207100654-55085f7c710a.2/go.mod h1:gUin8BTHrs/dRa0bdSHBb0twUODf4pUk4R9tPhOsPmc= -buf.build/gen/go/cosmos/ics23/protocolbuffers/go v1.28.1-20221207100654-55085f7c710a.4/go.mod h1:bASIBnznZv/r+XmEKQvGR5+1D+VkRjQG3K0mtlNL4l0= -buf.build/gen/go/cosmos/ics23/protocolbuffers/go v1.31.0-20221207100654-55085f7c710a.2/go.mod h1:1V7tFOxP2P2x8G0oasO+VqSHN0Bhly5I/e+2vENGomQ= -buf.build/gen/go/penumbra-zone/penumbra/grpc/go v1.3.0-20231120132728-bc443669626d.2/go.mod h1:f02cXVjnFw1swHvdrTWUfuH29d4UEl7mgVUg581vtXU= -buf.build/gen/go/penumbra-zone/penumbra/protocolbuffers/go v1.28.1-20231120132728-bc443669626d.4/go.mod h1:mbqAF6Y8Bzzf8D+vY21ktscpxes7AusdpvIW/slzsdI= -buf.build/gen/go/penumbra-zone/penumbra/protocolbuffers/go v1.31.0-20231120132728-bc443669626d.2 h1:IOCmnR+xxYcOUdG2fRR6KRAkATFKMJYE1Z5zVV1Pphg= -buf.build/gen/go/penumbra-zone/penumbra/protocolbuffers/go v1.31.0-20231120132728-bc443669626d.2/go.mod h1:h82VMeit0Ae3VmGvS6QH6yJx9GPHM3y4y0x1JU3Vyyc= +buf.build/gen/go/astria/astria/protocolbuffers/go v1.32.0-20240208041217-cec081a8099b.1 h1:fnyvaSUmCcM+Ono8mu4KuR7Al0rcgsrswHRUB/osTaI= +buf.build/gen/go/astria/astria/protocolbuffers/go v1.32.0-20240208041217-cec081a8099b.1/go.mod h1:HTIae3hIWhV69v7f8BJQzr2tP6yd0/gxwLrMiG306RY= +buf.build/gen/go/astria/execution-apis/grpc/go v1.3.0-20240207231045-2f6384a93a8d.2 h1:AjjfhXMKvUteizjKbLvE0wINSs7Zp/BhhdTBJTdXEJc= +buf.build/gen/go/astria/execution-apis/grpc/go v1.3.0-20240207231045-2f6384a93a8d.2/go.mod h1:LK1fGXWZLwItgvIjWjPyJkEoFvpQ6evGC/nyXlzwZw0= +buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.28.1-20240207231045-2f6384a93a8d.4/go.mod h1:5wxRDkWimPnuhDUA4pFBaHMtrViNJAHguLU1Wq8T6x8= +buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.32.0-20240207231045-2f6384a93a8d.1 h1:480dXLg2BTRFoXGVkCxUyOoS1v3dWn+LM77kRP30ZIU= +buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.32.0-20240207231045-2f6384a93a8d.1/go.mod h1:m409hJcO0kExqrFoQS8fQ7yXHuuM8JRTEYB+09WWVy0= +buf.build/gen/go/cosmos/cosmos-proto/protocolbuffers/go v1.32.0-20211202220400-1935555c206d.1/go.mod h1:GpU2rx3tDDSvCER8/rvvgu6s6LeMU73TKjfBZ89OZKg= +buf.build/gen/go/cosmos/cosmos-sdk/protocolbuffers/go v1.32.0-20230522115704-e7a85cef453e.1/go.mod h1:J8VpbpzO6pccEOWdLbYylDP8lRPifk2EA8tmJNkdZZo= +buf.build/gen/go/cosmos/cosmos-sdk/protocolbuffers/go v1.32.0-20230719110346-aa25660f4ff7.1/go.mod h1:Tl9HTTTqDT4kfcsEwfEyUeFdJmbcgSOXL2q50rG5XBw= +buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.32.0-20221020125208-34d970b699f8.1/go.mod h1:5GqIYthcy/ASmnKcaT26APpxMhZirnIHXHKki69zjWI= +buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.32.0-20230509103710-5e5b9fdd0180.1/go.mod h1:5GqIYthcy/ASmnKcaT26APpxMhZirnIHXHKki69zjWI= +buf.build/gen/go/cosmos/ibc/protocolbuffers/go v1.32.0-20230913112312-7ab44ae956a0.1/go.mod h1:IPgm3IicGPCXFRfFMLOgHFp3kexNEULuIzEJshSNPcY= +buf.build/gen/go/cosmos/ics23/protocolbuffers/go v1.32.0-20221207100654-55085f7c710a.1/go.mod h1:pjXPxEgmuc0apOM+/10DC/vWa3di1I0Z+CxwKqRXWYQ= +buf.build/gen/go/penumbra-zone/penumbra/protocolbuffers/go v1.32.0-20231120132728-bc443669626d.1/go.mod h1:HOI8VDE0aOk+R3EtXPICCUm0pO8D0PSnS7k2fFq2soE= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.31.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= @@ -2765,10 +2746,6 @@ google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6/go.mod h1:rZS5c/ZV google.golang.org/genproto v0.0.0-20221201164419-0e50fba7f41c/go.mod h1:rZS5c/ZVYMaOGBfO68GWtjOw/eLaZM1X6iVtgjZ+EWg= google.golang.org/genproto v0.0.0-20221202195650-67e5cbc046fd/go.mod h1:cTsE614GARnxrLsqKREzmNYJACSWWpAWdNMwnD7c2BE= google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= -google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 h1:wpZ8pe2x1Q3f2KyT5f8oP/fa9rHAKgFPr/HZdNuS+PQ= -google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:J7XzRzVy1+IPwWHZUzoD0IccYZIrXILAQpc+Qy9CMhY= -google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 h1:JpwMPBpFN3uKhdaekDpiNlImDdkUAyiJ6ez/uxGaUSo= -google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:0xJLfVdJqpAPl8tDg1ujOCGzx6LFLttXT5NhllGOXY4= google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f h1:ultW7fxlIvee4HYrtnaRPon9HpEgFk5zYpmfMgtKB5I= google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f/go.mod h1:L9KNLi232K1/xB6f7AlSX692koaRnKaWSR0stBki0Yc= google.golang.org/grpc v1.8.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= @@ -2839,7 +2816,6 @@ google.golang.org/protobuf v1.27.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= diff --git a/mempool/clist_mempool.go b/mempool/clist_mempool.go index b55bace70..3da6b0a58 100644 --- a/mempool/clist_mempool.go +++ b/mempool/clist_mempool.go @@ -240,7 +240,7 @@ func (mem *CListMempool) CheckTx( // (eg. after committing a block, txs are removed from mempool but not cache), // so we only record the sender for txs still in the mempool. if e, ok := mem.txsMap.Load(tx.Key()); ok { - memTx := e.(*clist.CElement).Value.(*mempoolTx) + memTx := e.(*clist.CElement).Value.(*MempoolTx) memTx.senders.LoadOrStore(txInfo.SenderID, true) // TODO: consider punishing peer for dups, // its non-trivial since invalid txs can become valid, @@ -316,7 +316,7 @@ func (mem *CListMempool) reqResCb( // Called from: // - resCbFirstTime (lock not held) if tx is valid -func (mem *CListMempool) addTx(memTx *mempoolTx) { +func (mem *CListMempool) addTx(memTx *MempoolTx) { e := mem.txs.PushBack(memTx) mem.txsMap.Store(memTx.tx.Key(), e) atomic.AddInt64(&mem.txsBytes, int64(len(memTx.tx))) @@ -336,7 +336,7 @@ func (mem *CListMempool) removeTx(tx types.Tx, elem *clist.CElement) { // RemoveTxByKey removes a transaction from the mempool by its TxKey index. func (mem *CListMempool) RemoveTxByKey(txKey types.TxKey) error { if e, ok := mem.txsMap.Load(txKey); ok { - memTx := e.(*clist.CElement).Value.(*mempoolTx) + memTx := e.(*clist.CElement).Value.(*MempoolTx) if memTx != nil { mem.removeTx(memTx.tx, e.(*clist.CElement)) return nil @@ -390,7 +390,7 @@ func (mem *CListMempool) resCbFirstTime( return } - memTx := &mempoolTx{ + memTx := &MempoolTx{ height: mem.height, gasWanted: r.CheckTx.GasWanted, tx: tx, @@ -435,7 +435,7 @@ func (mem *CListMempool) resCbRecheck(req *abci.Request, res *abci.Response) { switch r := res.Value.(type) { case *abci.Response_CheckTx: tx := req.GetCheckTx().Tx - memTx := mem.recheckCursor.Value.(*mempoolTx) + memTx := mem.recheckCursor.Value.(*MempoolTx) // Search through the remaining list of tx to recheck for a transaction that matches // the one we received from the ABCI application. @@ -462,7 +462,7 @@ func (mem *CListMempool) resCbRecheck(req *abci.Request, res *abci.Response) { } mem.recheckCursor = mem.recheckCursor.Next() - memTx = mem.recheckCursor.Value.(*mempoolTx) + memTx = mem.recheckCursor.Value.(*MempoolTx) } var postCheckErr error @@ -534,7 +534,7 @@ func (mem *CListMempool) ReapMaxBytesMaxGas(maxBytes, maxGas int64) types.Txs { // txs := make([]types.Tx, 0, cmtmath.MinInt(mem.txs.Len(), max/mem.avgTxSize)) txs := make([]types.Tx, 0, mem.txs.Len()) for e := mem.txs.Front(); e != nil; e = e.Next() { - memTx := e.Value.(*mempoolTx) + memTx := e.Value.(*MempoolTx) // Check total gas requirement and total size requirement. // If maxGas is negative, skip this check. // Since newTotalGas < masGas, which @@ -569,7 +569,7 @@ func (mem *CListMempool) ReapMaxTxs(max int) types.Txs { txs := make([]types.Tx, 0, length) for e := mem.txs.Front(); e != nil && len(txs) < max; e = e.Next() { - memTx := e.Value.(*mempoolTx) + memTx := e.Value.(*MempoolTx) txs = append(txs, memTx.tx) } return txs @@ -652,7 +652,7 @@ func (mem *CListMempool) recheckTxs() { // Push txs to proxyAppConn // NOTE: globalCb may be called concurrently. for e := mem.txs.Front(); e != nil; e = e.Next() { - memTx := e.Value.(*mempoolTx) + memTx := e.Value.(*MempoolTx) _, err := mem.proxyAppConn.CheckTxAsync(context.TODO(), &abci.RequestCheckTx{ Tx: memTx.tx, Type: abci.CheckTxType_Recheck, @@ -670,8 +670,8 @@ func (mem *CListMempool) recheckTxs() { //-------------------------------------------------------------------------------- -// mempoolTx is a transaction that successfully ran -type mempoolTx struct { +// MempoolTx is a transaction that successfully ran +type MempoolTx struct { height uint64 // height that this tx had been validated in gasWanted int64 // amount of gas this tx states it will require tx types.Tx // @@ -682,6 +682,10 @@ type mempoolTx struct { } // Height returns the height for this transaction -func (memTx *mempoolTx) Height() uint64 { +func (memTx *MempoolTx) Height() uint64 { return atomic.LoadUint64(&memTx.height) } + +func (memTx *MempoolTx) Tx() types.Tx { + return memTx.tx +} diff --git a/mempool/clist_mempool_test.go b/mempool/clist_mempool_test.go index a9ceac235..8314c2772 100644 --- a/mempool/clist_mempool_test.go +++ b/mempool/clist_mempool_test.go @@ -217,7 +217,7 @@ func TestReapMaxBytesMaxGas(t *testing.T) { // Ensure gas calculation behaves as expected checkTxs(t, mp, 1, UnknownPeerID) - tx0 := mp.TxsFront().Value.(*mempoolTx) + tx0 := mp.TxsFront().Value.(*MempoolTx) require.Equal(t, tx0.gasWanted, int64(1), "transactions gas was set incorrectly") // ensure each tx is 20 bytes long require.Equal(t, len(tx0.tx), 20, "Tx is longer than 20 bytes") diff --git a/node/full.go b/node/full.go index 9ab8b73d4..c9e2688d1 100644 --- a/node/full.go +++ b/node/full.go @@ -16,11 +16,9 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" - abci "github.com/cometbft/cometbft/abci/types" llcfg "github.com/cometbft/cometbft/config" "github.com/cometbft/cometbft/libs/log" "github.com/cometbft/cometbft/libs/service" - corep2p "github.com/cometbft/cometbft/p2p" proxy "github.com/cometbft/cometbft/proxy" rpcclient "github.com/cometbft/cometbft/rpc/client" cmtypes "github.com/cometbft/cometbft/types" @@ -31,7 +29,6 @@ import ( "github.com/rollkit/rollkit/block" "github.com/rollkit/rollkit/config" "github.com/rollkit/rollkit/mempool" - "github.com/rollkit/rollkit/p2p" "github.com/rollkit/rollkit/state" "github.com/rollkit/rollkit/state/indexer" blockidxkv "github.com/rollkit/rollkit/state/indexer/block/kv" @@ -44,7 +41,6 @@ import ( // prefixes used in KV store to separate main node data from DALC data var ( mainPrefix = "0" - dalcPrefix = "1" indexerPrefix = "2" // indexPrefix uses "i", so using "0-2" to avoid clash ) @@ -174,19 +170,17 @@ func newFullNode( } // init mempool reaper - sequencerAddr := "" - privateKeyBytes, err := hex.DecodeString("your_private_key_in_hex") + privateKeyBytes, err := hex.DecodeString(nodeConfig.Astria.SeqPrivate) if err != nil { return nil, err } - private := ed25519.PrivateKey(privateKeyBytes) - seqClient := sequencer.NewClient(sequencerAddr, private, genesis.ChainID) - reaper := astriamempool.NewMempoolReaper(seqClient, mempool) + private := ed25519.NewKeyFromSeed(privateKeyBytes) + seqClient := sequencer.NewClient(nodeConfig.Astria.SeqAddress, private, genesis.ChainID) + reaper := astriamempool.NewMempoolReaper(seqClient, mempool, logger) // init grpc execution api - executionAddr := ":50051" serviceV1a2 := execution.NewExecutionServiceServerV1Alpha2(blockManager, store, logger) - grpcServerHandler := execution.NewGRPCServerHandler(serviceV1a2, executionAddr) + grpcServerHandler := execution.NewGRPCServerHandler(serviceV1a2, nodeConfig.Astria.GrpcListen) node := &FullNode{ proxyApp: proxyApp, @@ -444,46 +438,6 @@ func (n *FullNode) AppClient() proxy.AppConns { return n.proxyApp } -// newTxValidator creates a pubsub validator that uses the node's mempool to check the -// transaction. If the transaction is valid, then it is added to the mempool -func (n *FullNode) newTxValidator(metrics *p2p.Metrics) p2p.GossipValidator { - return func(m *p2p.GossipMessage) bool { - n.Logger.Debug("transaction received", "bytes", len(m.Data)) - msgBytes := m.Data - labels := []string{ - "peer_id", m.From.String(), - "chID", n.genesis.ChainID, - } - metrics.PeerReceiveBytesTotal.With(labels...).Add(float64(len(msgBytes))) - metrics.MessageReceiveBytesTotal.With("message_type", "tx").Add(float64(len(msgBytes))) - checkTxResCh := make(chan *abci.ResponseCheckTx, 1) - err := n.Mempool.CheckTx(m.Data, func(resp *abci.ResponseCheckTx) { - select { - case <-n.ctx.Done(): - return - case checkTxResCh <- resp: - } - }, mempool.TxInfo{ - SenderID: n.mempoolIDs.GetForPeer(m.From), - SenderP2PID: corep2p.ID(m.From), - }) - switch { - case errors.Is(err, mempool.ErrTxInCache): - return true - case errors.Is(err, mempool.ErrMempoolIsFull{}): - return true - case errors.Is(err, mempool.ErrTxTooLarge{}): - return false - case errors.Is(err, mempool.ErrPreCheck{}): - return false - default: - } - checkTxResp := <-checkTxResCh - - return checkTxResp.Code == abci.CodeTypeOK - } -} - func newPrefixKV(kvStore ds.Datastore, prefix string) ds.TxnDatastore { return (ktds.Wrap(kvStore, ktds.PrefixTransform{Prefix: ds.NewKey(prefix)}).Children()[0]).(ds.TxnDatastore) } diff --git a/node/helpers.go b/node/helpers.go deleted file mode 100644 index 158fc200e..000000000 --- a/node/helpers.go +++ /dev/null @@ -1,144 +0,0 @@ -package node - -import ( - "errors" - "fmt" - "testing" - "time" - - testutils "github.com/celestiaorg/utils/test" - - "github.com/rollkit/rollkit/config" -) - -// Source is an enum representing different sources of height -type Source int - -const ( - // Header is the source of height from the header service - Header Source = iota - // Block is the source of height from the block service - Block - // Store is the source of height from the block manager store - Store -) - -// MockTester is a mock testing.T -type MockTester struct { - t *testing.T -} - -// Fail is used to fail the test -func (m MockTester) Fail() {} - -// FailNow is used to fail the test immediately -func (m MockTester) FailNow() {} - -// Logf is used to log a message to the test logger -func (m MockTester) Logf(format string, args ...interface{}) {} - -// Errorf is used to log an error to the test logger -func (m MockTester) Errorf(format string, args ...interface{}) {} - -func waitForFirstBlock(node Node, source Source) error { - return waitForAtLeastNBlocks(node, 1, source) -} - -func getBMConfig() config.BlockManagerConfig { - return config.BlockManagerConfig{ - DABlockTime: 100 * time.Millisecond, - BlockTime: 1 * time.Second, // blocks must be at least 1 sec apart for adjacent headers to get verified correctly - } -} - -func getNodeHeight(node Node, source Source) (uint64, error) { - switch source { - case Header: - return getNodeHeightFromHeader(node) - case Block: - return getNodeHeightFromBlock(node) - case Store: - return getNodeHeightFromStore(node) - default: - return 0, errors.New("invalid source") - } -} - -func isBlockHashSeen(node Node, blockHash string) bool { - if fn, ok := node.(*FullNode); ok { - return fn.blockManager.IsBlockHashSeen(blockHash) - } - return false -} - -func getNodeHeightFromHeader(node Node) (uint64, error) { - if fn, ok := node.(*FullNode); ok { - return fn.hSyncService.HeaderStore().Height(), nil - } - if ln, ok := node.(*LightNode); ok { - return ln.hSyncService.HeaderStore().Height(), nil - } - return 0, errors.New("not a full or light node") -} - -func getNodeHeightFromBlock(node Node) (uint64, error) { - if fn, ok := node.(*FullNode); ok { - return fn.bSyncService.BlockStore().Height(), nil - } - return 0, errors.New("not a full node") -} - -func getNodeHeightFromStore(node Node) (uint64, error) { - if fn, ok := node.(*FullNode); ok { - return fn.blockManager.GetStoreHeight(), nil - } - return 0, errors.New("not a full node") -} - -// safeClose closes the channel if it's not closed already -func safeClose(ch chan struct{}) { - select { - case <-ch: - default: - close(ch) - } -} - -func verifyNodesSynced(node1, node2 Node, source Source) error { - return testutils.Retry(300, 100*time.Millisecond, func() error { - n1Height, err := getNodeHeight(node1, source) - if err != nil { - return err - } - n2Height, err := getNodeHeight(node2, source) - if err != nil { - return err - } - if n1Height == n2Height { - return nil - } - return fmt.Errorf("nodes not synced: node1 at height %v, node2 at height %v", n1Height, n2Height) - }) -} - -func waitForAtLeastNBlocks(node Node, n int, source Source) error { - return testutils.Retry(300, 100*time.Millisecond, func() error { - nHeight, err := getNodeHeight(node, source) - if err != nil { - return err - } - if nHeight >= uint64(n) { - return nil - } - return fmt.Errorf("expected height > %v, got %v", n, nHeight) - }) -} - -func waitUntilBlockHashSeen(node Node, blockHash string) error { - return testutils.Retry(300, 100*time.Millisecond, func() error { - if isBlockHashSeen(node, blockHash) { - return nil - } - return fmt.Errorf("block hash %v not seen", blockHash) - }) -} diff --git a/node/helpers_test.go b/node/helpers_test.go deleted file mode 100644 index 676bbb47e..000000000 --- a/node/helpers_test.go +++ /dev/null @@ -1,98 +0,0 @@ -package node - -import ( - "context" - "crypto/rand" - "errors" - "testing" - "time" - - testutils "github.com/celestiaorg/utils/test" - "github.com/cometbft/cometbft/libs/log" - "github.com/libp2p/go-libp2p/core/crypto" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - goDATest "github.com/rollkit/go-da/test" - "github.com/rollkit/rollkit/da" -) - -func getMockDA() *da.DAClient { - return &da.DAClient{DA: goDATest.NewDummyDA(), GasPrice: -1, Logger: log.TestingLogger()} -} - -func TestMockTester(t *testing.T) { - m := MockTester{t} - m.Fail() - m.FailNow() - m.Logf("hello") - m.Errorf("goodbye") -} - -func TestGetNodeHeight(t *testing.T) { - require := require.New(t) - assert := assert.New(t) - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - dalc := getMockDA() - num := 2 - keys := make([]crypto.PrivKey, num) - for i := 0; i < num; i++ { - keys[i], _, _ = crypto.GenerateEd25519Key(rand.Reader) - } - bmConfig := getBMConfig() - fullNode, _ := createNode(ctx, 0, true, false, keys, bmConfig, t) - lightNode, _ := createNode(ctx, 1, true, true, keys, bmConfig, t) - fullNode.(*FullNode).dalc = dalc - fullNode.(*FullNode).blockManager.SetDALC(dalc) - require.NoError(fullNode.Start()) - defer func() { - assert.NoError(fullNode.Stop()) - }() - - assert.NoError(lightNode.Start()) - defer func() { - assert.NoError(lightNode.Stop()) - }() - - require.NoError(testutils.Retry(1000, 100*time.Millisecond, func() error { - num, err := getNodeHeight(fullNode, Header) - if err != nil { - return err - } - if num > 0 { - return nil - } - return errors.New("expected height > 0") - })) - require.NoError(testutils.Retry(1000, 100*time.Millisecond, func() error { - num, err := getNodeHeight(fullNode, Block) - if err != nil { - return err - } - if num > 0 { - return nil - } - return errors.New("expected height > 0") - })) - require.NoError(testutils.Retry(1000, 100*time.Millisecond, func() error { - num, err := getNodeHeight(fullNode, Store) - if err != nil { - return err - } - if num > 0 { - return nil - } - return errors.New("expected height > 0") - })) - require.NoError(testutils.Retry(1000, 100*time.Millisecond, func() error { - num, err := getNodeHeight(lightNode, Header) - if err != nil { - return err - } - if num > 0 { - return nil - } - return errors.New("expected height > 0") - })) -} diff --git a/node/light.go b/node/light.go deleted file mode 100644 index 062ba53b5..000000000 --- a/node/light.go +++ /dev/null @@ -1,144 +0,0 @@ -package node - -import ( - "context" - "errors" - "fmt" - - "github.com/cometbft/cometbft/libs/log" - "github.com/cometbft/cometbft/libs/service" - proxy "github.com/cometbft/cometbft/proxy" - rpcclient "github.com/cometbft/cometbft/rpc/client" - cmtypes "github.com/cometbft/cometbft/types" - ds "github.com/ipfs/go-datastore" - "github.com/libp2p/go-libp2p/core/crypto" - - "github.com/rollkit/rollkit/block" - "github.com/rollkit/rollkit/config" - "github.com/rollkit/rollkit/p2p" - "github.com/rollkit/rollkit/store" -) - -var _ Node = &LightNode{} - -// LightNode is a rollup node that only needs the header service -type LightNode struct { - service.BaseService - - P2P *p2p.Client - - proxyApp proxy.AppConns - - hSyncService *block.HeaderSyncService - - client rpcclient.Client - - ctx context.Context - cancel context.CancelFunc -} - -// GetClient returns a new rpcclient for the light node -func (ln *LightNode) GetClient() rpcclient.Client { - return ln.client -} - -func newLightNode( - ctx context.Context, - conf config.NodeConfig, - p2pKey crypto.PrivKey, - clientCreator proxy.ClientCreator, - genesis *cmtypes.GenesisDoc, - metricsProvider MetricsProvider, - logger log.Logger, -) (ln *LightNode, err error) { - // Create context with cancel so that all services using the context can - // catch the cancel signal when the node shutdowns - ctx, cancel := context.WithCancel(ctx) - defer func() { - // If there is an error, cancel the context - if err != nil { - cancel() - } - }() - - _, p2pMetrics, _, _, abciMetrics := metricsProvider(genesis.ChainID) - - // Create the proxyApp and establish connections to the ABCI app (consensus, mempool, query). - proxyApp := proxy.NewAppConns(clientCreator, abciMetrics) - proxyApp.SetLogger(logger.With("module", "proxy")) - if err := proxyApp.Start(); err != nil { - return nil, fmt.Errorf("error while starting proxy app connections: %v", err) - } - - datastore, err := openDatastore(conf, logger) - if err != nil { - return nil, err - } - client, err := p2p.NewClient(conf.P2P, p2pKey, genesis.ChainID, datastore, logger.With("module", "p2p"), p2pMetrics) - if err != nil { - return nil, err - } - - headerSyncService, err := block.NewHeaderSyncService(ctx, datastore, conf, genesis, client, logger.With("module", "HeaderSyncService")) - if err != nil { - return nil, fmt.Errorf("error while initializing HeaderSyncService: %w", err) - } - - node := &LightNode{ - P2P: client, - proxyApp: proxyApp, - hSyncService: headerSyncService, - cancel: cancel, - ctx: ctx, - } - - node.P2P.SetTxValidator(node.falseValidator()) - - node.BaseService = *service.NewBaseService(logger, "LightNode", node) - - node.client = NewLightClient(node) - - return node, nil -} - -func openDatastore(conf config.NodeConfig, logger log.Logger) (ds.TxnDatastore, error) { - if conf.RootDir == "" && conf.DBPath == "" { // this is used for testing - logger.Info("WARNING: working in in-memory mode") - return store.NewDefaultInMemoryKVStore() - } - return store.NewDefaultKVStore(conf.RootDir, conf.DBPath, "rollkit-light") -} - -// Cancel calls the underlying context's cancel function. -func (n *LightNode) Cancel() { - n.cancel() -} - -// OnStart starts the P2P and HeaderSync services -func (ln *LightNode) OnStart() error { - if err := ln.P2P.Start(ln.ctx); err != nil { - return err - } - - if err := ln.hSyncService.Start(); err != nil { - return fmt.Errorf("error while starting header sync service: %w", err) - } - - return nil -} - -// OnStop stops the light node -func (ln *LightNode) OnStop() { - ln.Logger.Info("halting light node...") - ln.cancel() - err := ln.P2P.Close() - err = errors.Join(err, ln.hSyncService.Stop()) - ln.Logger.Error("errors while stopping node:", "errors", err) -} - -// Dummy validator that always returns a callback function with boolean `false` -func (ln *LightNode) falseValidator() p2p.GossipValidator { - return func(*p2p.GossipMessage) bool { - return false - } -} diff --git a/node/light_client.go b/node/light_client.go deleted file mode 100644 index 526270b01..000000000 --- a/node/light_client.go +++ /dev/null @@ -1,192 +0,0 @@ -package node - -import ( - "context" - - cmbytes "github.com/cometbft/cometbft/libs/bytes" - rpcclient "github.com/cometbft/cometbft/rpc/client" - ctypes "github.com/cometbft/cometbft/rpc/core/types" - "github.com/cometbft/cometbft/types" -) - -var _ rpcclient.Client = &LightClient{} - -// LightClient is a Client interface for the LightNode -type LightClient struct { - types.EventBus - node *LightNode -} - -// NewLightClient returns a new LightClient for the LightNode -func NewLightClient(node *LightNode) *LightClient { - return &LightClient{ - node: node, - } -} - -// ABCIInfo returns basic information about application state. -func (c *LightClient) ABCIInfo(ctx context.Context) (*ctypes.ResultABCIInfo, error) { - panic("Not implemented") -} - -// ABCIQuery queries for data from application. -func (c *LightClient) ABCIQuery(ctx context.Context, path string, data cmbytes.HexBytes) (*ctypes.ResultABCIQuery, error) { - panic("Not implemented") -} - -// ABCIQueryWithOptions queries for data from application. -func (c *LightClient) ABCIQueryWithOptions(ctx context.Context, path string, data cmbytes.HexBytes, opts rpcclient.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) { - panic("Not implemented") -} - -// BroadcastTxCommit returns with the responses from CheckTx and DeliverTx. -// More: https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_commit -func (c *LightClient) BroadcastTxCommit(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) { - panic("Not implemented") -} - -// BroadcastTxAsync returns right away, with no response. Does not wait for -// CheckTx nor DeliverTx results. -// More: https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_async -func (c *LightClient) BroadcastTxAsync(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) { - panic("Not implemented") -} - -// BroadcastTxSync returns with the response from CheckTx. Does not wait for -// DeliverTx result. -// More: https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_sync -func (c *LightClient) BroadcastTxSync(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) { - panic("Not implemented") -} - -// Subscribe subscribe given subscriber to a query. -func (c *LightClient) Subscribe(ctx context.Context, subscriber, query string, outCapacity ...int) (out <-chan ctypes.ResultEvent, err error) { - panic("Not implemented") -} - -// Unsubscribe unsubscribes given subscriber from a query. -func (c *LightClient) Unsubscribe(ctx context.Context, subscriber, query string) error { - panic("Not implemented") -} - -// Genesis returns entire genesis. -func (c *LightClient) Genesis(_ context.Context) (*ctypes.ResultGenesis, error) { - panic("Not implemented") -} - -// GenesisChunked returns given chunk of genesis. -func (c *LightClient) GenesisChunked(context context.Context, id uint) (*ctypes.ResultGenesisChunk, error) { - panic("Not implemented") -} - -// BlockchainInfo returns ABCI block meta information for given height range. -func (c *LightClient) BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) { - panic("Not implemented") -} - -// NetInfo returns basic information about client P2P connections. -func (c *LightClient) NetInfo(ctx context.Context) (*ctypes.ResultNetInfo, error) { - panic("Not implemented") -} - -// DumpConsensusState always returns error as there is no consensus state in Rollkit. -func (c *LightClient) DumpConsensusState(ctx context.Context) (*ctypes.ResultDumpConsensusState, error) { - panic("Not implemented") -} - -// ConsensusState always returns error as there is no consensus state in Rollkit. -func (c *LightClient) ConsensusState(ctx context.Context) (*ctypes.ResultConsensusState, error) { - panic("Not implemented") -} - -// ConsensusParams returns consensus params at given height. -// -// Currently, consensus params changes are not supported and this method returns params as defined in genesis. -func (c *LightClient) ConsensusParams(ctx context.Context, height *int64) (*ctypes.ResultConsensusParams, error) { - panic("Not implemented") -} - -// Health endpoint returns empty value. It can be used to monitor service availability. -func (c *LightClient) Health(ctx context.Context) (*ctypes.ResultHealth, error) { - panic("Not implemented") -} - -// Block method returns BlockID and block itself for given height. -// -// If height is nil, it returns information about last known block. -func (c *LightClient) Block(ctx context.Context, height *int64) (*ctypes.ResultBlock, error) { - panic("Not implemented") -} - -// BlockByHash returns BlockID and block itself for given hash. -func (c *LightClient) BlockByHash(ctx context.Context, hash []byte) (*ctypes.ResultBlock, error) { - panic("Not implemented") -} - -// BlockResults returns information about transactions, events and updates of validator set and consensus params. -func (c *LightClient) BlockResults(ctx context.Context, height *int64) (*ctypes.ResultBlockResults, error) { - panic("Not implemented") -} - -// Commit returns signed header (aka commit) at given height. -func (c *LightClient) Commit(ctx context.Context, height *int64) (*ctypes.ResultCommit, error) { - panic("Not implemented") -} - -// Validators returns paginated list of validators at given height. -func (c *LightClient) Validators(ctx context.Context, heightPtr *int64, pagePtr, perPagePtr *int) (*ctypes.ResultValidators, error) { - panic("Not implemented") -} - -// Tx returns detailed information about transaction identified by its hash. -func (c *LightClient) Tx(ctx context.Context, hash []byte, prove bool) (*ctypes.ResultTx, error) { - panic("Not implemented") -} - -// TxSearch returns detailed information about transactions matching query. -func (c *LightClient) TxSearch(ctx context.Context, query string, prove bool, pagePtr, perPagePtr *int, orderBy string) (*ctypes.ResultTxSearch, error) { - panic("Not implemented") -} - -// BlockSearch defines a method to search for a paginated set of blocks by -// BeginBlock and EndBlock event search criteria. -func (c *LightClient) BlockSearch(ctx context.Context, query string, page, perPage *int, orderBy string) (*ctypes.ResultBlockSearch, error) { - panic("Not implemented") -} - -// Status returns detailed information about current status of the node. -func (c *LightClient) Status(ctx context.Context) (*ctypes.ResultStatus, error) { - panic("Not implemented") -} - -// BroadcastEvidence is not yet implemented. -func (c *LightClient) BroadcastEvidence(ctx context.Context, evidence types.Evidence) (*ctypes.ResultBroadcastEvidence, error) { - panic("Not implemented") -} - -// NumUnconfirmedTxs returns information about transactions in mempool. -func (c *LightClient) NumUnconfirmedTxs(ctx context.Context) (*ctypes.ResultUnconfirmedTxs, error) { - panic("Not implemented") -} - -// UnconfirmedTxs returns transactions in mempool. -func (c *LightClient) UnconfirmedTxs(ctx context.Context, limitPtr *int) (*ctypes.ResultUnconfirmedTxs, error) { - panic("Not implemented") -} - -// CheckTx executes a new transaction against the application to determine its validity. -// -// If valid, the tx is automatically added to the mempool. -func (c *LightClient) CheckTx(ctx context.Context, tx types.Tx) (*ctypes.ResultCheckTx, error) { - panic("Not implemented") -} - -// Header satisfies the client interface but is not implemented -func (c *LightClient) Header(ctx context.Context, height *int64) (*ctypes.ResultHeader, error) { - panic("Not implemented") -} - -// HeaderByHash satisfies the client interface but is not implemented -func (c *LightClient) HeaderByHash(ctx context.Context, hash cmbytes.HexBytes) (*ctypes.ResultHeader, error) { - panic("Not implemented") -} diff --git a/node/light_client_test.go b/node/light_client_test.go deleted file mode 100644 index a7b9576a4..000000000 --- a/node/light_client_test.go +++ /dev/null @@ -1,219 +0,0 @@ -package node - -import ( - "context" - "testing" - - rpcclient "github.com/cometbft/cometbft/rpc/client" - "github.com/stretchr/testify/assert" -) - -// TestLightClient_Panics tests that all methods of LightClient and ensures that -// they panic as they are not implemented. This is to ensure that when the -// methods are implemented in the future we don't forget to add testing. When -// methods are implemented, they should be removed from this test and have their -// own test written. -func TestLightClient_Panics(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - ln := initializeAndStartLightNode(ctx, t) - defer cleanUpNode(ln, t) - - tests := []struct { - name string - fn func() - }{ - { - name: "ABCIInfo", - fn: func() { - _, _ = ln.GetClient().ABCIInfo(ctx) - }, - }, - { - name: "ABCIQuery", - fn: func() { - _, _ = ln.GetClient().ABCIQuery(ctx, "", nil) - }, - }, - { - name: "ABCIQueryWithOptions", - fn: func() { - _, _ = ln.GetClient().ABCIQueryWithOptions(ctx, "", nil, rpcclient.ABCIQueryOptions{}) - }, - }, - { - name: "BroadcastTxCommit", - fn: func() { - _, _ = ln.GetClient().BroadcastTxSync(ctx, []byte{}) - }, - }, - { - name: "BroadcastTxAsync", - fn: func() { - _, _ = ln.GetClient().BroadcastTxSync(ctx, []byte{}) - }, - }, - { - name: "BroadcastTxSync", - fn: func() { - _, _ = ln.GetClient().BroadcastTxSync(ctx, []byte{}) - }, - }, - { - name: "Subscribe", - fn: func() { - _, _ = ln.GetClient().Subscribe(ctx, "", "", 0) - }, - }, - { - name: "Block", - fn: func() { - _, _ = ln.GetClient().Block(ctx, nil) - }, - }, - { - name: "BlockByHash", - fn: func() { - _, _ = ln.GetClient().BlockByHash(ctx, []byte{}) - }, - }, - { - name: "BlockResults", - fn: func() { - _, _ = ln.GetClient().BlockResults(ctx, nil) - }, - }, - { - name: "BlockSearch", - fn: func() { - _, _ = ln.GetClient().BlockSearch(ctx, "", nil, nil, "") - }, - }, - { - name: "BlockchainInfo", - fn: func() { - _, _ = ln.GetClient().BlockchainInfo(ctx, 0, 0) - }, - }, - { - name: "BroadcastEvidence", - fn: func() { - _, _ = ln.GetClient().BroadcastEvidence(ctx, nil) - }, - }, - { - name: "CheckTx", - fn: func() { - _, _ = ln.GetClient().CheckTx(ctx, []byte{}) - }, - }, - { - name: "Commit", - fn: func() { - _, _ = ln.GetClient().Commit(ctx, nil) - }, - }, - { - name: "ConsensusParams", - fn: func() { - _, _ = ln.GetClient().ConsensusParams(ctx, nil) - }, - }, - { - name: "ConsensusState", - fn: func() { - _, _ = ln.GetClient().ConsensusState(ctx) - }, - }, - { - name: "DumpConsensusState", - fn: func() { - _, _ = ln.GetClient().DumpConsensusState(ctx) - }, - }, - { - name: "Genesis", - fn: func() { - _, _ = ln.GetClient().Genesis(ctx) - }, - }, - { - name: "GenesisChunked", - fn: func() { - _, _ = ln.GetClient().GenesisChunked(ctx, 0) - }, - }, - { - name: "Header", - fn: func() { - _, _ = ln.GetClient().Header(ctx, nil) - }, - }, - { - name: "HeaderByHash", - fn: func() { - _, _ = ln.GetClient().HeaderByHash(ctx, []byte{}) - }, - }, - { - name: "Health", - fn: func() { - _, _ = ln.GetClient().Health(ctx) - }, - }, - { - name: "NetInfo", - fn: func() { - _, _ = ln.GetClient().NetInfo(ctx) - }, - }, - { - name: "NumUnconfirmedTxs", - fn: func() { - _, _ = ln.GetClient().NumUnconfirmedTxs(ctx) - }, - }, - { - name: "Status", - fn: func() { - _, _ = ln.GetClient().Status(ctx) - }, - }, - { - name: "Tx", - fn: func() { - _, _ = ln.GetClient().Tx(ctx, []byte{}, false) - }, - }, - { - name: "TxSearch", - fn: func() { - _, _ = ln.GetClient().TxSearch(ctx, "", false, nil, nil, "") - }, - }, - { - name: "UnconfirmedTxs", - fn: func() { - _, _ = ln.GetClient().UnconfirmedTxs(ctx, nil) - }, - }, - { - name: "Unsubscribe", - fn: func() { - _ = ln.GetClient().Unsubscribe(ctx, "", "") - }, - }, - { - name: "Validators", - fn: func() { - _, _ = ln.GetClient().Validators(ctx, nil, nil, nil) - }, - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - assert.Panics(t, test.fn) - }) - } -} diff --git a/node/node.go b/node/node.go index 63a373c18..2246b1b69 100644 --- a/node/node.go +++ b/node/node.go @@ -33,26 +33,14 @@ func NewNode( metricsProvider MetricsProvider, logger log.Logger, ) (Node, error) { - if !conf.Light { - return newFullNode( - ctx, - conf, - p2pKey, - signingKey, - appClient, - genesis, - metricsProvider, - logger, - ) - } else { - return newLightNode( - ctx, - conf, - p2pKey, - appClient, - genesis, - metricsProvider, - logger, - ) - } + return newFullNode( + ctx, + conf, + p2pKey, + signingKey, + appClient, + genesis, + metricsProvider, + logger, + ) }