From 0949fa23f52ba606cbcdaf7b040b55919d6b860b Mon Sep 17 00:00:00 2001 From: Alonso Rodriguez Date: Wed, 5 Apr 2023 22:33:49 +0200 Subject: [PATCH] remove broadcast service (#1988) --- Makefile | 1 - README.md | 6 +- ci/e2e-group2/broadcast_test.go | 1 - cmd/main.go | 2 - cmd/run.go | 20 - config/config.go | 2 - config/config_test.go | 12 - config/default.go | 5 - .../environments/local/local.node.config.toml | 5 - .../mainnet/public.node.config.toml | 1 - .../public/public.node.config.toml | 1 - docs/components/rpc.md | 1 - docs/json-rpc-endpoints.md | 1 - docs/modes.md | 1 - docs/networks.md | 6 +- jsonrpc/config.go | 3 - jsonrpc/endpoints_zkevm.go | 6 - jsonrpc/endpoints_zkevm.openrpc.json | 23 - proto/src/proto/broadcast/v1/broadcast.proto | 40 -- sequencer/broadcast/client.go | 31 -- sequencer/broadcast/config.go | 7 - sequencer/broadcast/interfaces.go | 18 - sequencer/broadcast/mocks/mock_state.go | 139 ------- sequencer/broadcast/pb/broadcast.pb.go | 393 ------------------ sequencer/broadcast/pb/broadcast_grpc.pb.go | 142 ------- sequencer/broadcast/server.go | 149 ------- sequencer/broadcast/server_test.go | 242 ----------- test/Makefile | 14 - test/config/debug.node.config.toml | 5 - test/config/test.node.config.toml | 5 - test/docker-compose.yml | 16 - test/e2e/broadcast_test.go | 167 -------- test/e2e/permissionlessrpc_test.go | 2 +- 33 files changed, 6 insertions(+), 1461 deletions(-) delete mode 120000 ci/e2e-group2/broadcast_test.go delete mode 100644 proto/src/proto/broadcast/v1/broadcast.proto delete mode 100644 sequencer/broadcast/client.go delete mode 100644 sequencer/broadcast/config.go delete mode 100644 sequencer/broadcast/interfaces.go delete mode 100644 sequencer/broadcast/mocks/mock_state.go delete mode 100644 sequencer/broadcast/pb/broadcast.pb.go delete mode 100644 sequencer/broadcast/pb/broadcast_grpc.pb.go delete mode 100644 sequencer/broadcast/server.go delete mode 100644 sequencer/broadcast/server_test.go delete mode 100644 test/e2e/broadcast_test.go diff --git a/Makefile b/Makefile index 0c800cfe54..83878cb65e 100644 --- a/Makefile +++ b/Makefile @@ -66,7 +66,6 @@ install-git-hooks: ## Moves hook files to the .git/hooks directory generate-code-from-proto: ## Generates code from proto files cd proto/src/proto/statedb/v1 && protoc --proto_path=. --proto_path=../../../../include --go_out=../../../../../merkletree/pb --go-grpc_out=../../../../../merkletree/pb --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative statedb.proto cd proto/src/proto/executor/v1 && protoc --proto_path=. --go_out=../../../../../state/runtime/executor/pb --go-grpc_out=../../../../../state/runtime/executor/pb --go-grpc_opt=paths=source_relative --go_opt=paths=source_relative executor.proto - cd proto/src/proto/broadcast/v1 && protoc --proto_path=. --proto_path=../../../../include --go_out=../../../../../sequencer/broadcast/pb --go-grpc_out=../../../../../sequencer/broadcast/pb --go-grpc_opt=paths=source_relative --go_opt=paths=source_relative broadcast.proto cd proto/src/proto/aggregator/v1 && protoc --proto_path=. --proto_path=../../../../include --go_out=../../../../../aggregator/pb --go-grpc_out=../../../../../aggregator/pb --go-grpc_opt=paths=source_relative --go_opt=paths=source_relative aggregator.proto ## Help display. diff --git a/README.md b/README.md index 003889e6c9..f4d362c6c7 100644 --- a/README.md +++ b/README.md @@ -34,11 +34,10 @@ The diagram represents the main components of the software and how they interact - (JSON) RPC: an interface that allows users (metamask, etherscan, ...) to interact with the node. Fully compatible with Ethereum RPC + some extra endpoints specifics of the network. It interacts with the `state` to get data and process transactions and with the `pool` to store transactions - Pool: DB that stores transactions by the `RPC` to be selected/discarded by the `sequencer` later on -- Trusted Sequencer: get transactions from the `pool`, check if they are valid by processing them using the `state`, and create sequences. Once transactions are added into the state, they are immediately available to the `broadcast` service. Sequences are sent to L1 using the `etherman` -- Broadcast: API used by the `synchronizer` of nodes that are not the `trusted sequencer` to synchronize the trusted state +- Trusted Sequencer: get transactions from the `pool`, check if they are valid by processing them using the `state`, and create sequences. Once transactions are added into the state, they are immediately available through the `rpc`. Sequences are sent to L1 using the `etherman` - Permissionless Sequencer: *coming soon* - Etherman: abstraction that implements the needed methods to interact with the Ethereum network and the relevant smart contracts. -- Synchronizer: Updates the `state` by fetching data from Ethereum through the `etherman`. If the node is not a `trusted sequencer` it also updates the state with the data fetched from the `broadcast` of the `trusted sequencer`. It also detects and handles reorgs that can happen if the `trusted sequencer` sends different data in the broadcast vs the sequences sent to L1 (trusted vs virtual state) +- Synchronizer: Updates the `state` by fetching data from Ethereum through the `etherman`. If the node is not a `trusted sequencer` it also updates the state with the data fetched from the `rpc` of the `trusted sequencer`. It also detects and handles reorgs that can happen if the `trusted sequencer` sends different data in the rpc vs the sequences sent to L1 (trusted vs virtual state) - State: Responsible for managing the state data (batches, blocks, transactions, ...) that is stored on the `state SB`. It also handles the integration with the `executor` and the `Merkletree` service - State DB: persistence layer for the state data (except the Merkletree that is handled by the `Merkletree` service) - Aggregator: consolidates batches by generating ZKPs (Zero Knowledge proofs). To do so it gathers the necessary data that the `prover` needs as input through the `state` and sends a request to it. Once the proof is generated it's sent to Ethereum through the `etherman` @@ -76,7 +75,6 @@ Required services and components: - JSON RPC: can run in a separated instance, and can have multiple instances - Sequencer & Synchronizer: single instance that needs to run together - Executor & Merkletree: service that can run on a separate instance -- Broadcast: can run on a separate instance - Pool DB: Postgres SQL that can be run in a separate instance - State DB: Postgres SQL that can be run in a separate instance diff --git a/ci/e2e-group2/broadcast_test.go b/ci/e2e-group2/broadcast_test.go deleted file mode 120000 index 404a0d32e5..0000000000 --- a/ci/e2e-group2/broadcast_test.go +++ /dev/null @@ -1 +0,0 @@ -../../test/e2e/broadcast_test.go \ No newline at end of file diff --git a/cmd/main.go b/cmd/main.go index d68c637ace..54a0efad7f 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -22,8 +22,6 @@ const ( RPC = "rpc" // SYNCHRONIZER is the synchronizer component identifier. SYNCHRONIZER = "synchronizer" - // BROADCAST is the broadcast component identifier. - BROADCAST = "broadcast-trusted-state" // ETHTXMANAGER is the service that manages the tx sent to L1 ETHTXMANAGER = "eth-tx-manager" // L2GASPRICER is the l2 gas pricer component identifier. diff --git a/cmd/run.go b/cmd/run.go index e7b230ed79..b6abc66d0f 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -29,8 +29,6 @@ import ( "github.com/0xPolygonHermez/zkevm-node/pool" "github.com/0xPolygonHermez/zkevm-node/pool/pgpoolstorage" "github.com/0xPolygonHermez/zkevm-node/sequencer" - "github.com/0xPolygonHermez/zkevm-node/sequencer/broadcast" - "github.com/0xPolygonHermez/zkevm-node/sequencer/broadcast/pb" "github.com/0xPolygonHermez/zkevm-node/state" "github.com/0xPolygonHermez/zkevm-node/state/runtime/executor" "github.com/0xPolygonHermez/zkevm-node/synchronizer" @@ -38,7 +36,6 @@ import ( "github.com/jackc/pgx/v4/pgxpool" "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/urfave/cli/v2" - "google.golang.org/grpc" ) const ( @@ -188,14 +185,6 @@ func start(cliCtx *cli.Context) error { } poolInstance := createPool(c.Pool, c.NetworkConfig.L2BridgeAddr, l2ChainID, st, eventLog) go runSynchronizer(*c, etherman, etm, st, poolInstance) - case BROADCAST: - ev.Component = event.Component_Broadcast - ev.Description = "Running broadcast service" - err := eventLog.LogEvent(ctx, ev) - if err != nil { - log.Fatal(err) - } - go runBroadcastServer(c.BroadcastServer, st) case ETHTXMANAGER: ev.Component = event.Component_EthTxManager ev.Description = "Running eth tx manager service" @@ -332,15 +321,6 @@ func runAggregator(ctx context.Context, c aggregator.Config, etherman *etherman. } } -func runBroadcastServer(c broadcast.ServerConfig, st *state.State) { - s := grpc.NewServer() - - broadcastSrv := broadcast.NewServer(&c, st) - pb.RegisterBroadcastServiceServer(s, broadcastSrv) - - broadcastSrv.Start() -} - // runL2GasPriceSuggester init gas price gasPriceEstimator based on type in config. func runL2GasPriceSuggester(cfg gasprice.Config, state *state.State, pool *pool.Pool, etherman *etherman.Client) { ctx := context.Background() diff --git a/config/config.go b/config/config.go index 317c8c3052..a8fe9288c2 100644 --- a/config/config.go +++ b/config/config.go @@ -18,7 +18,6 @@ import ( "github.com/0xPolygonHermez/zkevm-node/pool" "github.com/0xPolygonHermez/zkevm-node/pricegetter" "github.com/0xPolygonHermez/zkevm-node/sequencer" - "github.com/0xPolygonHermez/zkevm-node/sequencer/broadcast" "github.com/0xPolygonHermez/zkevm-node/state/runtime/executor" "github.com/0xPolygonHermez/zkevm-node/synchronizer" "github.com/mitchellh/mapstructure" @@ -64,7 +63,6 @@ type Config struct { NetworkConfig NetworkConfig L2GasPriceSuggester gasprice.Config Executor executor.Config - BroadcastServer broadcast.ServerConfig MTClient merkletree.Config StateDB db.Config Metrics metrics.Config diff --git a/config/config_test.go b/config/config_test.go index 6b8a062593..d896170edb 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -322,10 +322,6 @@ func Test_Defaults(t *testing.T) { path: "RPC.MaxRequestsPerIPAndSecond", expectedValue: float64(50), }, - { - path: "RPC.BroadcastURI", - expectedValue: "127.0.0.1:61090", - }, { path: "RPC.DefaultSenderAddress", expectedValue: "0x1111111111111111111111111111111111111111", @@ -347,14 +343,6 @@ func Test_Defaults(t *testing.T) { path: "Executor.URI", expectedValue: "127.0.0.1:50071", }, - { - path: "BroadcastServer.Host", - expectedValue: "0.0.0.0", - }, - { - path: "BroadcastServer.Port", - expectedValue: 61090, - }, { path: "Metrics.Host", expectedValue: "0.0.0.0", diff --git a/config/default.go b/config/default.go index 4489d900c8..2f3ee051d4 100644 --- a/config/default.go +++ b/config/default.go @@ -56,7 +56,6 @@ ReadTimeoutInSec = 60 WriteTimeoutInSec = 60 MaxRequestsPerIPAndSecond = 50 SequencerNodeURI = "" -BroadcastURI = "127.0.0.1:61090" DefaultSenderAddress = "0x1111111111111111111111111111111111111111" EnableL2SuggestedGasPricePolling = true [RPC.WebSockets] @@ -142,10 +141,6 @@ URI = "127.0.0.1:50061" [Executor] URI = "127.0.0.1:50071" -[BroadcastServer] -Host = "0.0.0.0" -Port = 61090 - [Metrics] Host = "0.0.0.0" Port = 9091 diff --git a/config/environments/local/local.node.config.toml b/config/environments/local/local.node.config.toml index 973ef37315..bd4cf37821 100644 --- a/config/environments/local/local.node.config.toml +++ b/config/environments/local/local.node.config.toml @@ -47,7 +47,6 @@ ReadTimeoutInSec = 60 WriteTimeoutInSec = 60 MaxRequestsPerIPAndSecond = 5000 SequencerNodeURI = "https://internal.zkevm-test.net:2083/" -BroadcastURI = "internal.zkevm-test.net:61090" DefaultSenderAddress = "0x1111111111111111111111111111111111111111" EnableL2SuggestedGasPricePolling = true [RPC.WebSockets] @@ -134,10 +133,6 @@ URI = "zkevm-prover:50061" [Executor] URI = "zkevm-prover:50071" -[BroadcastServer] -Host = "0.0.0.0" -Port = 61090 - [Metrics] Host = "0.0.0.0" Port = 9091 diff --git a/config/environments/mainnet/public.node.config.toml b/config/environments/mainnet/public.node.config.toml index 6bbcdee9e9..16f52a458d 100644 --- a/config/environments/mainnet/public.node.config.toml +++ b/config/environments/mainnet/public.node.config.toml @@ -45,7 +45,6 @@ ReadTimeoutInSec = 60 WriteTimeoutInSec = 60 MaxRequestsPerIPAndSecond = 5000 SequencerNodeURI = "https://zkevm-rpc.com" -BroadcastURI = "broadcast.zkevm-rpc.com:61090" DefaultSenderAddress = "0x1111111111111111111111111111111111111111" EnableL2SuggestedGasPricePolling = false [RPC.WebSockets] diff --git a/config/environments/public/public.node.config.toml b/config/environments/public/public.node.config.toml index fcf64af9f1..6a968cd9d1 100644 --- a/config/environments/public/public.node.config.toml +++ b/config/environments/public/public.node.config.toml @@ -45,7 +45,6 @@ ReadTimeoutInSec = 60 WriteTimeoutInSec = 60 MaxRequestsPerIPAndSecond = 5000 SequencerNodeURI = "https://rpc.public.zkevm-test.net/" -BroadcastURI = "public-grpc.zkevm-test.net:61090" DefaultSenderAddress = "0x1111111111111111111111111111111111111111" EnableL2SuggestedGasPricePolling = false [RPC.WebSockets] diff --git a/docs/components/rpc.md b/docs/components/rpc.md index 87fe246bc1..3725ed0436 100644 --- a/docs/components/rpc.md +++ b/docs/components/rpc.md @@ -40,7 +40,6 @@ The container alone needs some parameters configured, access to certain configur - `ZKEVM_NODE_STATEDB_HOST`: Name of StateDB Database Host - `ZKEVM_NODE_POOL_HOST`: Name of PoolDB Database Host - `ZKEVM_NODE_RPC_DB_HOST`: Name of RPCDB Database Host - - `ZKEVM_NODE_RPC_BROADCASTURI`: String to return when a client requests the following resource: `zkevm_getBroadcastURI` - volumes: - `your config.toml file`: /app/config.toml - `your genesis file`: /app/genesis.json diff --git a/docs/json-rpc-endpoints.md b/docs/json-rpc-endpoints.md index 1af3b4e3db..b3e8de763b 100644 --- a/docs/json-rpc-endpoints.md +++ b/docs/json-rpc-endpoints.md @@ -60,7 +60,6 @@ If the endpoint is not in the list below, it means this specific endpoint is not - `zkevm_batchNumberByBlockNumber` - `zkevm_consolidatedBlockNumber` - `zkevm_getBatchByNumber` -- `zkevm_getBroadcastURI` _* deprecated, will be removed in the future_ - `zkevm_isBlockConsolidated` - `zkevm_isBlockVirtualized` - `zkevm_verifiedBatchNumber` diff --git a/docs/modes.md b/docs/modes.md index 3230a0e471..d14510dad8 100644 --- a/docs/modes.md +++ b/docs/modes.md @@ -25,7 +25,6 @@ Use the default [public config file](https://github.com/0xPolygonHermez/zkevm-no [RPC] ... SequencerNodeURI = "https://public.zkevm-test.net:2083" -BroadcastURI = "public-grpc.zkevm-test.net:61090" ``` Same goes for the Prover Config ([prover-config.json](https://github.com/0xPolygonHermez/zkevm-node/blob/develop/config/environments/public/public.prover.config.json)): diff --git a/docs/networks.md b/docs/networks.md index 78f738ed7c..d4ce7c907c 100644 --- a/docs/networks.md +++ b/docs/networks.md @@ -1,5 +1,5 @@ # zkEVM testnet networks -| Network Name | ChainID | RPC URL | Explorer | Bridge Info | Broadcast RPC URI | -|--------------|---------|---------|----------|------------------|-----| -| Public Testnet | `1402` | https://rpc.public.zkevm-test.net | https://explorer.public.zkevm-test.net | https://public.zkevm-test.net/ | `public-grpc.zkevm-test.net:61090` +| Network Name | ChainID | RPC URL | Explorer | Bridge Info | +|--------------|---------|---------|----------|------------------| +| Public Testnet | `1402` | https://rpc.public.zkevm-test.net | https://explorer.public.zkevm-test.net | https://public.zkevm-test.net/ \ No newline at end of file diff --git a/jsonrpc/config.go b/jsonrpc/config.go index 70f0587cf5..555d969eaa 100644 --- a/jsonrpc/config.go +++ b/jsonrpc/config.go @@ -17,9 +17,6 @@ type Config struct { // to relay transactions to the Sequencer node SequencerNodeURI string `mapstructure:"SequencerNodeURI"` - // BroadcastURI is the URL of the Trusted State broadcast service - BroadcastURI string `mapstructure:"BroadcastURI"` - // DefaultSenderAddress is the address that jRPC will use // to communicate with the state for eth_EstimateGas and eth_Call when // the From field is not specified because it is optional diff --git a/jsonrpc/endpoints_zkevm.go b/jsonrpc/endpoints_zkevm.go index 063188ea9f..2471fbec57 100644 --- a/jsonrpc/endpoints_zkevm.go +++ b/jsonrpc/endpoints_zkevm.go @@ -167,9 +167,3 @@ func (z *ZKEVMEndpoints) GetBatchByNumber(batchNumber types.BatchNumber, fullTx return rpcBatch, nil }) } - -// GetBroadcastURI returns the IP:PORT of the broadcast service provided -// by the Trusted Sequencer JSON RPC server -func (z *ZKEVMEndpoints) GetBroadcastURI() (interface{}, types.Error) { - return z.config.BroadcastURI, nil -} diff --git a/jsonrpc/endpoints_zkevm.openrpc.json b/jsonrpc/endpoints_zkevm.openrpc.json index c6bc43860b..0f205fc39c 100644 --- a/jsonrpc/endpoints_zkevm.openrpc.json +++ b/jsonrpc/endpoints_zkevm.openrpc.json @@ -82,29 +82,6 @@ } ] }, - { - "name": "zkevm_getBroadcastURI", - "summary": "Returns the configured Broadcast URL of the Trusted Sequencer.", - "params": [], - "result": { - "name": "result", - "schema": { - "type": "string" - } - }, - "examples": [ - { - "name": "example", - "description": "", - "params": [], - "result": { - "name": "exampleResult", - "description": "", - "value": "https://broadcast:1111" - } - } - ] - }, { "name": "zkevm_batchNumber", "summary": "Returns the latest batch number.", diff --git a/proto/src/proto/broadcast/v1/broadcast.proto b/proto/src/proto/broadcast/v1/broadcast.proto deleted file mode 100644 index 5879506600..0000000000 --- a/proto/src/proto/broadcast/v1/broadcast.proto +++ /dev/null @@ -1,40 +0,0 @@ -/** -* Broadcast service. -**/ - -syntax = "proto3"; - -import "google/protobuf/empty.proto"; - -package broadcast.v1; - -option go_package = "github.com/0xPolygonHermez/zkevm-node/sequencer/broadcast/pb"; - -service BroadcastService { - rpc GetLastBatch(google.protobuf.Empty) returns (GetBatchResponse); - rpc GetBatch(GetBatchRequest) returns (GetBatchResponse); -} - -// Requests -message GetBatchRequest { - uint64 batch_number = 1; -} - -// Responses -message GetBatchResponse { - uint64 batch_number = 1; - string global_exit_root = 2; - string local_exit_root = 3; - string state_root = 4; - string mainnet_exit_root = 5; - string rollup_exit_root = 6; - uint64 timestamp = 7; - string sequencer = 8; - uint64 forced_batch_number = 9; - repeated Transaction transactions = 10; -} - -// Common -message Transaction { - string encoded = 1; -} diff --git a/sequencer/broadcast/client.go b/sequencer/broadcast/client.go deleted file mode 100644 index 5a0c750a6e..0000000000 --- a/sequencer/broadcast/client.go +++ /dev/null @@ -1,31 +0,0 @@ -package broadcast - -import ( - "context" - "time" - - "github.com/0xPolygonHermez/zkevm-node/log" - "github.com/0xPolygonHermez/zkevm-node/sequencer/broadcast/pb" - "google.golang.org/grpc" - "google.golang.org/grpc/credentials/insecure" -) - -// NewClient creates a grpc client to communicates with the Broadcast server -func NewClient(ctx context.Context, serverAddress string) (pb.BroadcastServiceClient, *grpc.ClientConn, context.CancelFunc, error) { - opts := []grpc.DialOption{ - grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithBlock(), - } - const maxWaitSeconds = 120 - ctx2, cancel := context.WithTimeout(ctx, maxWaitSeconds*time.Second) - log.Infof("connecting to broadcast service: %v", serverAddress) - conn, err := grpc.DialContext(ctx2, serverAddress, opts...) - if err != nil { - log.Errorf("failed to connect to broadcast service: %v", err) - return nil, nil, cancel, err - } - client := pb.NewBroadcastServiceClient(conn) - log.Info("connected to broadcast service") - - return client, conn, cancel, nil -} diff --git a/sequencer/broadcast/config.go b/sequencer/broadcast/config.go deleted file mode 100644 index 8023fcfaee..0000000000 --- a/sequencer/broadcast/config.go +++ /dev/null @@ -1,7 +0,0 @@ -package broadcast - -// ServerConfig represents the configuration of the broadcast server. -type ServerConfig struct { - Host string `mapstructure:"Host"` - Port int `mapstructure:"Port"` -} diff --git a/sequencer/broadcast/interfaces.go b/sequencer/broadcast/interfaces.go deleted file mode 100644 index c0f3c267de..0000000000 --- a/sequencer/broadcast/interfaces.go +++ /dev/null @@ -1,18 +0,0 @@ -package broadcast - -import ( - "context" - - "github.com/0xPolygonHermez/zkevm-node/state" - "github.com/ethereum/go-ethereum/common" - "github.com/jackc/pgx/v4" -) - -// Consumer interfaces required by the package. - -type stateInterface interface { - GetLastBatch(ctx context.Context, dbTx pgx.Tx) (*state.Batch, error) - GetBatchByNumber(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) (*state.Batch, error) - GetEncodedTransactionsByBatchNumber(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) (encoded []string, err error) - GetExitRootByGlobalExitRoot(ctx context.Context, ger common.Hash, dbTx pgx.Tx) (*state.GlobalExitRoot, error) -} diff --git a/sequencer/broadcast/mocks/mock_state.go b/sequencer/broadcast/mocks/mock_state.go deleted file mode 100644 index a01e3386ea..0000000000 --- a/sequencer/broadcast/mocks/mock_state.go +++ /dev/null @@ -1,139 +0,0 @@ -// Code generated by mockery v2.22.1. DO NOT EDIT. - -package mocks - -import ( - context "context" - - common "github.com/ethereum/go-ethereum/common" - - mock "github.com/stretchr/testify/mock" - - pgx "github.com/jackc/pgx/v4" - - state "github.com/0xPolygonHermez/zkevm-node/state" -) - -// StateMock is an autogenerated mock type for the stateInterface type -type StateMock struct { - mock.Mock -} - -// GetBatchByNumber provides a mock function with given fields: ctx, batchNumber, dbTx -func (_m *StateMock) GetBatchByNumber(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) (*state.Batch, error) { - ret := _m.Called(ctx, batchNumber, dbTx) - - var r0 *state.Batch - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, uint64, pgx.Tx) (*state.Batch, error)); ok { - return rf(ctx, batchNumber, dbTx) - } - if rf, ok := ret.Get(0).(func(context.Context, uint64, pgx.Tx) *state.Batch); ok { - r0 = rf(ctx, batchNumber, dbTx) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*state.Batch) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, uint64, pgx.Tx) error); ok { - r1 = rf(ctx, batchNumber, dbTx) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// GetEncodedTransactionsByBatchNumber provides a mock function with given fields: ctx, batchNumber, dbTx -func (_m *StateMock) GetEncodedTransactionsByBatchNumber(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) ([]string, error) { - ret := _m.Called(ctx, batchNumber, dbTx) - - var r0 []string - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, uint64, pgx.Tx) ([]string, error)); ok { - return rf(ctx, batchNumber, dbTx) - } - if rf, ok := ret.Get(0).(func(context.Context, uint64, pgx.Tx) []string); ok { - r0 = rf(ctx, batchNumber, dbTx) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]string) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, uint64, pgx.Tx) error); ok { - r1 = rf(ctx, batchNumber, dbTx) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// GetExitRootByGlobalExitRoot provides a mock function with given fields: ctx, ger, dbTx -func (_m *StateMock) GetExitRootByGlobalExitRoot(ctx context.Context, ger common.Hash, dbTx pgx.Tx) (*state.GlobalExitRoot, error) { - ret := _m.Called(ctx, ger, dbTx) - - var r0 *state.GlobalExitRoot - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, common.Hash, pgx.Tx) (*state.GlobalExitRoot, error)); ok { - return rf(ctx, ger, dbTx) - } - if rf, ok := ret.Get(0).(func(context.Context, common.Hash, pgx.Tx) *state.GlobalExitRoot); ok { - r0 = rf(ctx, ger, dbTx) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*state.GlobalExitRoot) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, common.Hash, pgx.Tx) error); ok { - r1 = rf(ctx, ger, dbTx) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// GetLastBatch provides a mock function with given fields: ctx, dbTx -func (_m *StateMock) GetLastBatch(ctx context.Context, dbTx pgx.Tx) (*state.Batch, error) { - ret := _m.Called(ctx, dbTx) - - var r0 *state.Batch - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, pgx.Tx) (*state.Batch, error)); ok { - return rf(ctx, dbTx) - } - if rf, ok := ret.Get(0).(func(context.Context, pgx.Tx) *state.Batch); ok { - r0 = rf(ctx, dbTx) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*state.Batch) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, pgx.Tx) error); ok { - r1 = rf(ctx, dbTx) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -type mockConstructorTestingTNewStateMock interface { - mock.TestingT - Cleanup(func()) -} - -// NewStateMock creates a new instance of StateMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewStateMock(t mockConstructorTestingTNewStateMock) *StateMock { - mock := &StateMock{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/sequencer/broadcast/pb/broadcast.pb.go b/sequencer/broadcast/pb/broadcast.pb.go deleted file mode 100644 index 35553231e5..0000000000 --- a/sequencer/broadcast/pb/broadcast.pb.go +++ /dev/null @@ -1,393 +0,0 @@ -//* -// Broadcast service. - -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.28.1 -// protoc v3.21.12 -// source: broadcast.proto - -package pb - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - emptypb "google.golang.org/protobuf/types/known/emptypb" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -// Requests -type GetBatchRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - BatchNumber uint64 `protobuf:"varint,1,opt,name=batch_number,json=batchNumber,proto3" json:"batch_number,omitempty"` -} - -func (x *GetBatchRequest) Reset() { - *x = GetBatchRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_broadcast_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *GetBatchRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*GetBatchRequest) ProtoMessage() {} - -func (x *GetBatchRequest) ProtoReflect() protoreflect.Message { - mi := &file_broadcast_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use GetBatchRequest.ProtoReflect.Descriptor instead. -func (*GetBatchRequest) Descriptor() ([]byte, []int) { - return file_broadcast_proto_rawDescGZIP(), []int{0} -} - -func (x *GetBatchRequest) GetBatchNumber() uint64 { - if x != nil { - return x.BatchNumber - } - return 0 -} - -// Responses -type GetBatchResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - BatchNumber uint64 `protobuf:"varint,1,opt,name=batch_number,json=batchNumber,proto3" json:"batch_number,omitempty"` - GlobalExitRoot string `protobuf:"bytes,2,opt,name=global_exit_root,json=globalExitRoot,proto3" json:"global_exit_root,omitempty"` - LocalExitRoot string `protobuf:"bytes,3,opt,name=local_exit_root,json=localExitRoot,proto3" json:"local_exit_root,omitempty"` - StateRoot string `protobuf:"bytes,4,opt,name=state_root,json=stateRoot,proto3" json:"state_root,omitempty"` - MainnetExitRoot string `protobuf:"bytes,5,opt,name=mainnet_exit_root,json=mainnetExitRoot,proto3" json:"mainnet_exit_root,omitempty"` - RollupExitRoot string `protobuf:"bytes,6,opt,name=rollup_exit_root,json=rollupExitRoot,proto3" json:"rollup_exit_root,omitempty"` - Timestamp uint64 `protobuf:"varint,7,opt,name=timestamp,proto3" json:"timestamp,omitempty"` - Sequencer string `protobuf:"bytes,8,opt,name=sequencer,proto3" json:"sequencer,omitempty"` - ForcedBatchNumber uint64 `protobuf:"varint,9,opt,name=forced_batch_number,json=forcedBatchNumber,proto3" json:"forced_batch_number,omitempty"` - Transactions []*Transaction `protobuf:"bytes,10,rep,name=transactions,proto3" json:"transactions,omitempty"` -} - -func (x *GetBatchResponse) Reset() { - *x = GetBatchResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_broadcast_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *GetBatchResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*GetBatchResponse) ProtoMessage() {} - -func (x *GetBatchResponse) ProtoReflect() protoreflect.Message { - mi := &file_broadcast_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use GetBatchResponse.ProtoReflect.Descriptor instead. -func (*GetBatchResponse) Descriptor() ([]byte, []int) { - return file_broadcast_proto_rawDescGZIP(), []int{1} -} - -func (x *GetBatchResponse) GetBatchNumber() uint64 { - if x != nil { - return x.BatchNumber - } - return 0 -} - -func (x *GetBatchResponse) GetGlobalExitRoot() string { - if x != nil { - return x.GlobalExitRoot - } - return "" -} - -func (x *GetBatchResponse) GetLocalExitRoot() string { - if x != nil { - return x.LocalExitRoot - } - return "" -} - -func (x *GetBatchResponse) GetStateRoot() string { - if x != nil { - return x.StateRoot - } - return "" -} - -func (x *GetBatchResponse) GetMainnetExitRoot() string { - if x != nil { - return x.MainnetExitRoot - } - return "" -} - -func (x *GetBatchResponse) GetRollupExitRoot() string { - if x != nil { - return x.RollupExitRoot - } - return "" -} - -func (x *GetBatchResponse) GetTimestamp() uint64 { - if x != nil { - return x.Timestamp - } - return 0 -} - -func (x *GetBatchResponse) GetSequencer() string { - if x != nil { - return x.Sequencer - } - return "" -} - -func (x *GetBatchResponse) GetForcedBatchNumber() uint64 { - if x != nil { - return x.ForcedBatchNumber - } - return 0 -} - -func (x *GetBatchResponse) GetTransactions() []*Transaction { - if x != nil { - return x.Transactions - } - return nil -} - -// Common -type Transaction struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Encoded string `protobuf:"bytes,1,opt,name=encoded,proto3" json:"encoded,omitempty"` -} - -func (x *Transaction) Reset() { - *x = Transaction{} - if protoimpl.UnsafeEnabled { - mi := &file_broadcast_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Transaction) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Transaction) ProtoMessage() {} - -func (x *Transaction) ProtoReflect() protoreflect.Message { - mi := &file_broadcast_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Transaction.ProtoReflect.Descriptor instead. -func (*Transaction) Descriptor() ([]byte, []int) { - return file_broadcast_proto_rawDescGZIP(), []int{2} -} - -func (x *Transaction) GetEncoded() string { - if x != nil { - return x.Encoded - } - return "" -} - -var File_broadcast_proto protoreflect.FileDescriptor - -var file_broadcast_proto_rawDesc = []byte{ - 0x0a, 0x0f, 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x12, 0x0c, 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74, 0x2e, 0x76, 0x31, 0x1a, - 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, - 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x34, 0x0a, 0x0f, - 0x47, 0x65, 0x74, 0x42, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, - 0x21, 0x0a, 0x0c, 0x62, 0x61, 0x74, 0x63, 0x68, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x62, 0x61, 0x74, 0x63, 0x68, 0x4e, 0x75, 0x6d, 0x62, - 0x65, 0x72, 0x22, 0xa7, 0x03, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x42, 0x61, 0x74, 0x63, 0x68, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x62, 0x61, 0x74, 0x63, 0x68, - 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x62, - 0x61, 0x74, 0x63, 0x68, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x28, 0x0a, 0x10, 0x67, 0x6c, - 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x65, 0x78, 0x69, 0x74, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x45, 0x78, 0x69, 0x74, - 0x52, 0x6f, 0x6f, 0x74, 0x12, 0x26, 0x0a, 0x0f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x5f, 0x65, 0x78, - 0x69, 0x74, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x45, 0x78, 0x69, 0x74, 0x52, 0x6f, 0x6f, 0x74, 0x12, 0x1d, 0x0a, 0x0a, - 0x73, 0x74, 0x61, 0x74, 0x65, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x09, 0x73, 0x74, 0x61, 0x74, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x12, 0x2a, 0x0a, 0x11, 0x6d, - 0x61, 0x69, 0x6e, 0x6e, 0x65, 0x74, 0x5f, 0x65, 0x78, 0x69, 0x74, 0x5f, 0x72, 0x6f, 0x6f, 0x74, - 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x6d, 0x61, 0x69, 0x6e, 0x6e, 0x65, 0x74, 0x45, - 0x78, 0x69, 0x74, 0x52, 0x6f, 0x6f, 0x74, 0x12, 0x28, 0x0a, 0x10, 0x72, 0x6f, 0x6c, 0x6c, 0x75, - 0x70, 0x5f, 0x65, 0x78, 0x69, 0x74, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x0e, 0x72, 0x6f, 0x6c, 0x6c, 0x75, 0x70, 0x45, 0x78, 0x69, 0x74, 0x52, 0x6f, 0x6f, - 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x07, - 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, - 0x1c, 0x0a, 0x09, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x72, 0x18, 0x08, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x09, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x72, 0x12, 0x2e, 0x0a, - 0x13, 0x66, 0x6f, 0x72, 0x63, 0x65, 0x64, 0x5f, 0x62, 0x61, 0x74, 0x63, 0x68, 0x5f, 0x6e, 0x75, - 0x6d, 0x62, 0x65, 0x72, 0x18, 0x09, 0x20, 0x01, 0x28, 0x04, 0x52, 0x11, 0x66, 0x6f, 0x72, 0x63, - 0x65, 0x64, 0x42, 0x61, 0x74, 0x63, 0x68, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x3d, 0x0a, - 0x0c, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x0a, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74, 0x2e, - 0x76, 0x31, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0c, - 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0x27, 0x0a, 0x0b, - 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x65, - 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x65, 0x6e, - 0x63, 0x6f, 0x64, 0x65, 0x64, 0x32, 0xa5, 0x01, 0x0a, 0x10, 0x42, 0x72, 0x6f, 0x61, 0x64, 0x63, - 0x61, 0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x46, 0x0a, 0x0c, 0x47, 0x65, - 0x74, 0x4c, 0x61, 0x73, 0x74, 0x42, 0x61, 0x74, 0x63, 0x68, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, - 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, - 0x74, 0x79, 0x1a, 0x1e, 0x2e, 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74, 0x2e, 0x76, - 0x31, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x49, 0x0a, 0x08, 0x47, 0x65, 0x74, 0x42, 0x61, 0x74, 0x63, 0x68, 0x12, 0x1d, - 0x2e, 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, - 0x74, 0x42, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, - 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, - 0x42, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x3e, 0x5a, - 0x3c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x30, 0x78, 0x50, 0x6f, - 0x6c, 0x79, 0x67, 0x6f, 0x6e, 0x48, 0x65, 0x72, 0x6d, 0x65, 0x7a, 0x2f, 0x7a, 0x6b, 0x65, 0x76, - 0x6d, 0x2d, 0x6e, 0x6f, 0x64, 0x65, 0x2f, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x72, - 0x2f, 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_broadcast_proto_rawDescOnce sync.Once - file_broadcast_proto_rawDescData = file_broadcast_proto_rawDesc -) - -func file_broadcast_proto_rawDescGZIP() []byte { - file_broadcast_proto_rawDescOnce.Do(func() { - file_broadcast_proto_rawDescData = protoimpl.X.CompressGZIP(file_broadcast_proto_rawDescData) - }) - return file_broadcast_proto_rawDescData -} - -var file_broadcast_proto_msgTypes = make([]protoimpl.MessageInfo, 3) -var file_broadcast_proto_goTypes = []interface{}{ - (*GetBatchRequest)(nil), // 0: broadcast.v1.GetBatchRequest - (*GetBatchResponse)(nil), // 1: broadcast.v1.GetBatchResponse - (*Transaction)(nil), // 2: broadcast.v1.Transaction - (*emptypb.Empty)(nil), // 3: google.protobuf.Empty -} -var file_broadcast_proto_depIdxs = []int32{ - 2, // 0: broadcast.v1.GetBatchResponse.transactions:type_name -> broadcast.v1.Transaction - 3, // 1: broadcast.v1.BroadcastService.GetLastBatch:input_type -> google.protobuf.Empty - 0, // 2: broadcast.v1.BroadcastService.GetBatch:input_type -> broadcast.v1.GetBatchRequest - 1, // 3: broadcast.v1.BroadcastService.GetLastBatch:output_type -> broadcast.v1.GetBatchResponse - 1, // 4: broadcast.v1.BroadcastService.GetBatch:output_type -> broadcast.v1.GetBatchResponse - 3, // [3:5] is the sub-list for method output_type - 1, // [1:3] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name -} - -func init() { file_broadcast_proto_init() } -func file_broadcast_proto_init() { - if File_broadcast_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_broadcast_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetBatchRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_broadcast_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetBatchResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_broadcast_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Transaction); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_broadcast_proto_rawDesc, - NumEnums: 0, - NumMessages: 3, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_broadcast_proto_goTypes, - DependencyIndexes: file_broadcast_proto_depIdxs, - MessageInfos: file_broadcast_proto_msgTypes, - }.Build() - File_broadcast_proto = out.File - file_broadcast_proto_rawDesc = nil - file_broadcast_proto_goTypes = nil - file_broadcast_proto_depIdxs = nil -} diff --git a/sequencer/broadcast/pb/broadcast_grpc.pb.go b/sequencer/broadcast/pb/broadcast_grpc.pb.go deleted file mode 100644 index af11613e42..0000000000 --- a/sequencer/broadcast/pb/broadcast_grpc.pb.go +++ /dev/null @@ -1,142 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. -// versions: -// - protoc-gen-go-grpc v1.2.0 -// - protoc v3.21.12 -// source: broadcast.proto - -package pb - -import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" - emptypb "google.golang.org/protobuf/types/known/emptypb" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.32.0 or later. -const _ = grpc.SupportPackageIsVersion7 - -// BroadcastServiceClient is the client API for BroadcastService service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type BroadcastServiceClient interface { - GetLastBatch(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*GetBatchResponse, error) - GetBatch(ctx context.Context, in *GetBatchRequest, opts ...grpc.CallOption) (*GetBatchResponse, error) -} - -type broadcastServiceClient struct { - cc grpc.ClientConnInterface -} - -func NewBroadcastServiceClient(cc grpc.ClientConnInterface) BroadcastServiceClient { - return &broadcastServiceClient{cc} -} - -func (c *broadcastServiceClient) GetLastBatch(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*GetBatchResponse, error) { - out := new(GetBatchResponse) - err := c.cc.Invoke(ctx, "/broadcast.v1.BroadcastService/GetLastBatch", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *broadcastServiceClient) GetBatch(ctx context.Context, in *GetBatchRequest, opts ...grpc.CallOption) (*GetBatchResponse, error) { - out := new(GetBatchResponse) - err := c.cc.Invoke(ctx, "/broadcast.v1.BroadcastService/GetBatch", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// BroadcastServiceServer is the server API for BroadcastService service. -// All implementations must embed UnimplementedBroadcastServiceServer -// for forward compatibility -type BroadcastServiceServer interface { - GetLastBatch(context.Context, *emptypb.Empty) (*GetBatchResponse, error) - GetBatch(context.Context, *GetBatchRequest) (*GetBatchResponse, error) - mustEmbedUnimplementedBroadcastServiceServer() -} - -// UnimplementedBroadcastServiceServer must be embedded to have forward compatible implementations. -type UnimplementedBroadcastServiceServer struct { -} - -func (UnimplementedBroadcastServiceServer) GetLastBatch(context.Context, *emptypb.Empty) (*GetBatchResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetLastBatch not implemented") -} -func (UnimplementedBroadcastServiceServer) GetBatch(context.Context, *GetBatchRequest) (*GetBatchResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetBatch not implemented") -} -func (UnimplementedBroadcastServiceServer) mustEmbedUnimplementedBroadcastServiceServer() {} - -// UnsafeBroadcastServiceServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to BroadcastServiceServer will -// result in compilation errors. -type UnsafeBroadcastServiceServer interface { - mustEmbedUnimplementedBroadcastServiceServer() -} - -func RegisterBroadcastServiceServer(s grpc.ServiceRegistrar, srv BroadcastServiceServer) { - s.RegisterService(&BroadcastService_ServiceDesc, srv) -} - -func _BroadcastService_GetLastBatch_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(emptypb.Empty) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(BroadcastServiceServer).GetLastBatch(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/broadcast.v1.BroadcastService/GetLastBatch", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(BroadcastServiceServer).GetLastBatch(ctx, req.(*emptypb.Empty)) - } - return interceptor(ctx, in, info, handler) -} - -func _BroadcastService_GetBatch_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(GetBatchRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(BroadcastServiceServer).GetBatch(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/broadcast.v1.BroadcastService/GetBatch", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(BroadcastServiceServer).GetBatch(ctx, req.(*GetBatchRequest)) - } - return interceptor(ctx, in, info, handler) -} - -// BroadcastService_ServiceDesc is the grpc.ServiceDesc for BroadcastService service. -// It's only intended for direct use with grpc.RegisterService, -// and not to be introspected or modified (even as a copy) -var BroadcastService_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "broadcast.v1.BroadcastService", - HandlerType: (*BroadcastServiceServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "GetLastBatch", - Handler: _BroadcastService_GetLastBatch_Handler, - }, - { - MethodName: "GetBatch", - Handler: _BroadcastService_GetBatch_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "broadcast.proto", -} diff --git a/sequencer/broadcast/server.go b/sequencer/broadcast/server.go deleted file mode 100644 index 6e53f69c4d..0000000000 --- a/sequencer/broadcast/server.go +++ /dev/null @@ -1,149 +0,0 @@ -package broadcast - -import ( - "context" - "fmt" - "net" - - "github.com/0xPolygonHermez/zkevm-node/log" - "github.com/0xPolygonHermez/zkevm-node/sequencer/broadcast/pb" - "github.com/0xPolygonHermez/zkevm-node/state" - "google.golang.org/grpc" - "google.golang.org/grpc/health/grpc_health_v1" - "google.golang.org/protobuf/types/known/emptypb" -) - -// Server provides the functionality of the Broadcast service. -type Server struct { - cfg *ServerConfig - - srv *grpc.Server - pb.UnimplementedBroadcastServiceServer - state stateInterface -} - -// NewServer is the Broadcast server constructor. -func NewServer(cfg *ServerConfig, state stateInterface) *Server { - return &Server{ - cfg: cfg, - state: state, - } -} - -// SetState is the state setter. -func (s *Server) SetState(st stateInterface) { - s.state = st -} - -// Start sets up the server to process requests. -func (s *Server) Start() { - address := fmt.Sprintf("%s:%d", s.cfg.Host, s.cfg.Port) - lis, err := net.Listen("tcp", address) - if err != nil { - log.Fatalf("failed to listen: %v", err) - } - - s.srv = grpc.NewServer() - pb.RegisterBroadcastServiceServer(s.srv, s) - - healthService := newHealthChecker() - grpc_health_v1.RegisterHealthServer(s.srv, healthService) - - log.Infof("Server listening in %q", address) - if err := s.srv.Serve(lis); err != nil { - log.Fatalf("failed to serve: %v", err) - } -} - -// Stop stops the server. -func (s *Server) Stop() { - s.srv.Stop() -} - -// Implementation of pb.BroadcastServiceServer interface methods. - -// GetBatch returns a batch by batch number. -func (s *Server) GetBatch(ctx context.Context, in *pb.GetBatchRequest) (*pb.GetBatchResponse, error) { - batch, err := s.state.GetBatchByNumber(ctx, in.BatchNumber, nil) - if err != nil { - return nil, err - } - return s.genericGetBatch(ctx, batch) -} - -// GetLastBatch returns the last batch. -func (s *Server) GetLastBatch(ctx context.Context, empty *emptypb.Empty) (*pb.GetBatchResponse, error) { - batch, err := s.state.GetLastBatch(ctx, nil) - if err != nil { - return nil, err - } - return s.genericGetBatch(ctx, batch) -} - -func (s *Server) genericGetBatch(ctx context.Context, batch *state.Batch) (*pb.GetBatchResponse, error) { - txs, err := s.state.GetEncodedTransactionsByBatchNumber(ctx, batch.BatchNumber, nil) - if err != nil { - return nil, err - } - transactions := make([]*pb.Transaction, len(txs)) - for i, tx := range txs { - transactions[i] = &pb.Transaction{ - Encoded: tx, - } - } - - var mainnetExitRoot, rollupExitRoot string - ger, err := s.state.GetExitRootByGlobalExitRoot(ctx, batch.GlobalExitRoot, nil) - if err == nil { - mainnetExitRoot = ger.MainnetExitRoot.String() - rollupExitRoot = ger.RollupExitRoot.String() - } else if err != state.ErrNotFound { - return nil, err - } - var fb uint64 - if batch.ForcedBatchNum != nil { - fb = *batch.ForcedBatchNum - } - - return &pb.GetBatchResponse{ - BatchNumber: batch.BatchNumber, - GlobalExitRoot: batch.GlobalExitRoot.String(), - Sequencer: batch.Coinbase.String(), - LocalExitRoot: batch.LocalExitRoot.String(), - StateRoot: batch.StateRoot.String(), - MainnetExitRoot: mainnetExitRoot, - RollupExitRoot: rollupExitRoot, - Timestamp: uint64(batch.Timestamp.Unix()), - Transactions: transactions, - ForcedBatchNumber: fb, - }, nil -} - -// HealthChecker will provide an implementation of the HealthCheck interface. -type healthChecker struct{} - -// NewHealthChecker returns a health checker according to standard package -// grpc.health.v1. -func newHealthChecker() *healthChecker { - return &healthChecker{} -} - -// HealthCheck interface implementation. - -// Check returns the current status of the server for unary gRPC health requests, -// for now if the server is up and able to respond we will always return SERVING. -func (s *healthChecker) Check(ctx context.Context, req *grpc_health_v1.HealthCheckRequest) (*grpc_health_v1.HealthCheckResponse, error) { - log.Info("Serving the Check request for health check") - return &grpc_health_v1.HealthCheckResponse{ - Status: grpc_health_v1.HealthCheckResponse_SERVING, - }, nil -} - -// Watch returns the current status of the server for stream gRPC health requests, -// for now if the server is up and able to respond we will always return SERVING. -func (s *healthChecker) Watch(req *grpc_health_v1.HealthCheckRequest, server grpc_health_v1.Health_WatchServer) error { - log.Info("Serving the Watch request for health check") - return server.Send(&grpc_health_v1.HealthCheckResponse{ - Status: grpc_health_v1.HealthCheckResponse_SERVING, - }) -} diff --git a/sequencer/broadcast/server_test.go b/sequencer/broadcast/server_test.go deleted file mode 100644 index 71d2d8c276..0000000000 --- a/sequencer/broadcast/server_test.go +++ /dev/null @@ -1,242 +0,0 @@ -package broadcast_test - -import ( - "context" - "errors" - "fmt" - "os" - "path" - "runtime" - "testing" - "time" - - "github.com/0xPolygonHermez/zkevm-node/sequencer/broadcast" - "github.com/0xPolygonHermez/zkevm-node/sequencer/broadcast/mocks" - "github.com/0xPolygonHermez/zkevm-node/sequencer/broadcast/pb" - "github.com/0xPolygonHermez/zkevm-node/state" - "github.com/0xPolygonHermez/zkevm-node/test/operations" - "github.com/0xPolygonHermez/zkevm-node/test/testutils" - "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" - "google.golang.org/grpc" - "google.golang.org/grpc/credentials/insecure" - "google.golang.org/protobuf/types/known/emptypb" -) - -const ( - host = "0.0.0.0" - port = 61091 -) - -var ( - address = fmt.Sprintf("%s:%d", host, port) - broadcastSrv *broadcast.Server - conn *grpc.ClientConn - cancel context.CancelFunc - err error - ctx = context.Background() -) - -func init() { - // Change dir to project root - // This is important because we have relative paths to files containing test vectors - _, filename, _, _ := runtime.Caller(0) - dir := path.Join(path.Dir(filename), "../../") - err := os.Chdir(dir) - if err != nil { - panic(err) - } -} - -func TestMain(m *testing.M) { - initialize() - defer teardown() - - os.Exit(m.Run()) -} - -func initialize() { - broadcastSrv = initBroadcastServer() - go broadcastSrv.Start() - - conn, cancel, err = initConn() - if err != nil { - panic(err) - } - - err = operations.WaitGRPCHealthy(address) - if err != nil { - panic(err) - } -} - -func teardown() { - cancel() - broadcastSrv.Stop() -} - -func initConn() (*grpc.ClientConn, context.CancelFunc, error) { - opts := []grpc.DialOption{ - grpc.WithTransportCredentials(insecure.NewCredentials()), - } - ctx, cancel := context.WithTimeout(ctx, 1*time.Second) - conn, err := grpc.DialContext(ctx, address, opts...) - return conn, cancel, err -} - -func initBroadcastServer() *broadcast.Server { - s := grpc.NewServer() - st := new(mocks.StateMock) - cfg := &broadcast.ServerConfig{ - Host: host, - Port: port, - } - - broadcastSrv = broadcast.NewServer(cfg, st) - pb.RegisterBroadcastServiceServer(s, broadcastSrv) - - return broadcastSrv -} - -func TestBroadcastServerGetBatch(t *testing.T) { - tcs := []struct { - description string - inputBatchNumber uint64 - expectedBatch *state.Batch - expectedForcedBatch *state.ForcedBatch - expectedEncodedTxs []string - expectedGER *state.GlobalExitRoot - expectedErr bool - expectedErrMsg string - }{ - { - description: "happy path", - inputBatchNumber: 14, - expectedBatch: &state.Batch{ - BatchNumber: 14, - GlobalExitRoot: common.HexToHash("a"), - Timestamp: time.Now(), - }, - expectedForcedBatch: &state.ForcedBatch{ - ForcedBatchNumber: 1, - }, - expectedEncodedTxs: []string{"tx1", "tx2", "tx3"}, - expectedGER: &state.GlobalExitRoot{ - MainnetExitRoot: common.HexToHash("b"), - RollupExitRoot: common.HexToHash("c"), - }, - }, - { - description: "query errors are returned", - inputBatchNumber: 14, - expectedErr: true, - expectedErrMsg: "query error", - }, - } - - for _, tc := range tcs { - tc := tc - t.Run(tc.description, func(t *testing.T) { - st := new(mocks.StateMock) - var err error - if tc.expectedErr { - err = errors.New(tc.expectedErrMsg) - } - st.On("GetBatchByNumber", mock.AnythingOfType("*context.valueCtx"), tc.inputBatchNumber, nil).Return(tc.expectedBatch, err) - st.On("GetEncodedTransactionsByBatchNumber", mock.AnythingOfType("*context.valueCtx"), tc.inputBatchNumber, nil).Return(tc.expectedEncodedTxs, err) - if tc.expectedBatch != nil { - st.On("GetExitRootByGlobalExitRoot", mock.AnythingOfType("*context.valueCtx"), tc.expectedBatch.GlobalExitRoot, nil).Return(tc.expectedGER, err) - } - broadcastSrv.SetState(st) - - client := pb.NewBroadcastServiceClient(conn) - actualBatch, err := client.GetBatch(ctx, &pb.GetBatchRequest{ - BatchNumber: tc.inputBatchNumber, - }) - require.NoError(t, testutils.CheckError(err, tc.expectedErr, fmt.Sprintf("rpc error: code = Unknown desc = %s", tc.expectedErrMsg))) - - if err == nil { - require.Equal(t, tc.expectedBatch.BatchNumber, actualBatch.BatchNumber) - require.Equal(t, tc.expectedBatch.GlobalExitRoot.String(), actualBatch.GlobalExitRoot) - require.Equal(t, uint64(tc.expectedBatch.Timestamp.Unix()), actualBatch.Timestamp) - for i, encoded := range tc.expectedEncodedTxs { - require.Equal(t, encoded, actualBatch.Transactions[i].Encoded) - } - require.Equal(t, tc.expectedGER.MainnetExitRoot.String(), actualBatch.MainnetExitRoot) - require.Equal(t, tc.expectedGER.RollupExitRoot.String(), actualBatch.RollupExitRoot) - - require.True(t, st.AssertExpectations(t)) - } - }) - } -} - -func TestBroadcastServerGetLastBatch(t *testing.T) { - tcs := []struct { - description string - expectedBatch *state.Batch - expectedForcedBatch *state.ForcedBatch - expectedEncodedTxs []string - expectedGER *state.GlobalExitRoot - expectedErr bool - expectedErrMsg string - }{ - { - description: "happy path", - expectedBatch: &state.Batch{ - BatchNumber: 14, - GlobalExitRoot: common.HexToHash("a"), - Timestamp: time.Now(), - }, - expectedForcedBatch: &state.ForcedBatch{ - ForcedBatchNumber: 1, - }, - expectedEncodedTxs: []string{"tx1", "tx2", "tx3"}, - expectedGER: &state.GlobalExitRoot{ - MainnetExitRoot: common.HexToHash("b"), - RollupExitRoot: common.HexToHash("c"), - }, - }, - { - description: "query errors are returned", - expectedErr: true, - expectedErrMsg: "query error", - }, - } - - for _, tc := range tcs { - tc := tc - t.Run(tc.description, func(t *testing.T) { - st := new(mocks.StateMock) - var err error - if tc.expectedErr { - err = errors.New(tc.expectedErrMsg) - } - st.On("GetLastBatch", mock.AnythingOfType("*context.valueCtx"), nil).Return(tc.expectedBatch, err) - if tc.expectedBatch != nil { - st.On("GetEncodedTransactionsByBatchNumber", mock.AnythingOfType("*context.valueCtx"), tc.expectedBatch.BatchNumber, nil).Return(tc.expectedEncodedTxs, err) - st.On("GetExitRootByGlobalExitRoot", mock.AnythingOfType("*context.valueCtx"), tc.expectedBatch.GlobalExitRoot, nil).Return(tc.expectedGER, err) - } - - broadcastSrv.SetState(st) - - client := pb.NewBroadcastServiceClient(conn) - actualBatch, err := client.GetLastBatch(ctx, &emptypb.Empty{}) - require.NoError(t, testutils.CheckError(err, tc.expectedErr, fmt.Sprintf("rpc error: code = Unknown desc = %s", tc.expectedErrMsg))) - - if err == nil { - require.Equal(t, tc.expectedBatch.BatchNumber, actualBatch.BatchNumber) - require.Equal(t, tc.expectedBatch.GlobalExitRoot.String(), actualBatch.GlobalExitRoot) - require.Equal(t, uint64(tc.expectedBatch.Timestamp.Unix()), actualBatch.Timestamp) - for i, encoded := range tc.expectedEncodedTxs { - require.Equal(t, encoded, actualBatch.Transactions[i].Encoded) - } - require.Equal(t, tc.expectedGER.MainnetExitRoot.String(), actualBatch.MainnetExitRoot) - require.Equal(t, tc.expectedGER.RollupExitRoot.String(), actualBatch.RollupExitRoot) - - require.True(t, st.AssertExpectations(t)) - } - }) - } -} diff --git a/test/Makefile b/test/Makefile index f4941b80cf..5c3925de5b 100644 --- a/test/Makefile +++ b/test/Makefile @@ -4,7 +4,6 @@ DOCKERCOMPOSEAPPL2GASP := zkevm-l2gaspricer DOCKERCOMPOSEAPPAGG := zkevm-aggregator DOCKERCOMPOSEAPPRPC := zkevm-json-rpc DOCKERCOMPOSEAPPSYNC := zkevm-sync -DOCKERCOMPOSEAPPBROADCAST := zkevm-broadcast DOCKERCOMPOSEAPPETHTXMANAGER := zkevm-eth-tx-manager DOCKERCOMPOSESTATEDB := zkevm-state-db DOCKERCOMPOSEPOOLDB := zkevm-pool-db @@ -32,7 +31,6 @@ RUNL2GASPRICER := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSEAPPL2GASP) RUNAGGREGATOR := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSEAPPAGG) RUNJSONRPC := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSEAPPRPC) RUNSYNC := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSEAPPSYNC) -RUNBROADCAST := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSEAPPBROADCAST) RUNETHTXMANAGER := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSEAPPETHTXMANAGER) RUNGRAFANA := DOCKERGID=`stat -c '%g' /var/run/docker.sock` $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSEGRAFANA) @@ -63,7 +61,6 @@ STOPL2GASPRICER := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEAPPL2GASP) && $(DOCKERCO STOPAGGREGATOR := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEAPPAGG) && $(DOCKERCOMPOSE) rm -f $(DOCKERCOMPOSEAPPAGG) STOPJSONRPC := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEAPPRPC) && $(DOCKERCOMPOSE) rm -f $(DOCKERCOMPOSEAPPRPC) STOPSYNC := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEAPPSYNC) && $(DOCKERCOMPOSE) rm -f $(DOCKERCOMPOSEAPPSYNC) -STOPBROADCAST := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEAPPBROADCAST) && $(DOCKERCOMPOSE) rm -f $(DOCKERCOMPOSEAPPBROADCAST) STOPETHTXMANAGER := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEAPPETHTXMANAGER) && $(DOCKERCOMPOSE) rm -f $(DOCKERCOMPOSEAPPETHTXMANAGER) STOPGRAFANA := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEGRAFANA) && $(DOCKERCOMPOSE) rm -f $(DOCKERCOMPOSEGRAFANA) @@ -236,7 +233,6 @@ run-node: ## Runs the node $(RUNL2GASPRICER) $(RUNAGGREGATOR) $(RUNJSONRPC) - $(RUNBROADCAST) .PHONY: stop-node stop-node: ## Stops the node @@ -246,7 +242,6 @@ stop-node: ## Stops the node $(STOPAGGREGATOR) $(STOPSYNC) $(STOPETHTXMANAGER) - $(STOPBROADCAST) .PHONY: run-network run-network: ## Runs the l1 network @@ -344,14 +339,6 @@ run-l2gaspricer: ## runs the L2 Gas Price component stop-l2gaspricer: ## stops the L2 Gas Price component $(STOPL2GASPRICER) -.PHONY: run-broadcast -run-broadcast: ## Runs the broadcast service - $(RUNBROADCAST) - -.PHONY: stop-broadcast -stop-broadcast: ## Stops the broadcast service - $(STOPBROADCAST) - .PHONY: run-eth-tx-manager run-eth-tx-manager: ## Runs the eth tx manager service $(RUNETHTXMANAGER) @@ -470,7 +457,6 @@ generate-mocks: ## Generates mocks for the tests, using mockery tool mockery --name=Tx --srcpkg=github.com/jackc/pgx/v4 --output=../sequencer --outpkg=sequencer --structname=DbTxMock --filename=mock_dbtx.go mockery --name=dbManagerInterface --dir=../sequencer --output=../sequencer --outpkg=sequencer --inpackage --structname=DbManagerMock --filename=mock_db_manager.go mockery --name=etherman --dir=../sequencer --output=../sequencer --outpkg=sequencer --inpackage --structname=EthermanMock --filename=mock_etherman.go - mockery --name=stateInterface --dir=../sequencer/broadcast --output=../sequencer/broadcast/mocks --outpkg=mocks --structname=StateMock --filename=mock_state.go mockery --name=ethermanInterface --dir=../synchronizer --output=../synchronizer --outpkg=synchronizer --structname=ethermanMock --filename=mock_etherman.go mockery --name=stateInterface --dir=../synchronizer --output=../synchronizer --outpkg=synchronizer --structname=stateMock --filename=mock_state.go diff --git a/test/config/debug.node.config.toml b/test/config/debug.node.config.toml index 94f1ff6cbd..75e0991720 100644 --- a/test/config/debug.node.config.toml +++ b/test/config/debug.node.config.toml @@ -47,7 +47,6 @@ ReadTimeoutInSec = 60 WriteTimeoutInSec = 60 MaxRequestsPerIPAndSecond = 10000 SequencerNodeURI = "" -BroadcastURI = "127.0.0.1:61090" DefaultSenderAddress = "0x1111111111111111111111111111111111111111" EnableL2SuggestedGasPricePolling = true [RPC.WebSockets] @@ -134,10 +133,6 @@ URI = "127.0.0.1:50061" [Executor] URI = "127.0.0.1:50071" -[BroadcastServer] -Host = "0.0.0.0" -Port = 61090 - [Metrics] Host = "0.0.0.0" Port = 9091 diff --git a/test/config/test.node.config.toml b/test/config/test.node.config.toml index eac76c6f21..4b880611ae 100644 --- a/test/config/test.node.config.toml +++ b/test/config/test.node.config.toml @@ -47,7 +47,6 @@ ReadTimeoutInSec = 60 WriteTimeoutInSec = 60 MaxRequestsPerIPAndSecond = 5000 SequencerNodeURI = "" -BroadcastURI = "127.0.0.1:61090" DefaultSenderAddress = "0x1111111111111111111111111111111111111111" EnableL2SuggestedGasPricePolling = true [RPC.WebSockets] @@ -136,10 +135,6 @@ URI = "zkevm-prover:50061" [Executor] URI = "zkevm-prover:50071" -[BroadcastServer] -Host = "0.0.0.0" -Port = 61090 - [Metrics] Host = "0.0.0.0" Port = 9091 diff --git a/test/docker-compose.yml b/test/docker-compose.yml index 78bea4e515..23e0d8c2e3 100644 --- a/test/docker-compose.yml +++ b/test/docker-compose.yml @@ -74,7 +74,6 @@ services: environment: - ZKEVM_NODE_STATEDB_HOST=zkevm-state-db - ZKEVM_NODE_POOL_DB_HOST=zkevm-pool-db - - ZKEVM_NODE_RPC_BROADCASTURI=zkevm-broadcast:61090 volumes: - ./config/test.node.config.toml:/app/config.toml - ./config/test.genesis.config.json:/app/genesis.json @@ -113,21 +112,6 @@ services: - "-c" - "/app/zkevm-node run --genesis /app/genesis.json --cfg /app/config.toml --components synchronizer" - zkevm-broadcast: - container_name: zkevm-broadcast - image: zkevm-node - environment: - - ZKEVM_NODE_STATEDB_HOST=zkevm-state-db - ports: - - 61090:61090 - volumes: - - ./config/test.node.config.toml:/app/config.toml - - ./config/test.genesis.config.json:/app/genesis.json - command: - - "/bin/sh" - - "-c" - - "/app/zkevm-node run --genesis /app/genesis.json --cfg /app/config.toml --components broadcast-trusted-state" - zkevm-eth-tx-manager: container_name: zkevm-eth-tx-manager image: zkevm-node diff --git a/test/e2e/broadcast_test.go b/test/e2e/broadcast_test.go deleted file mode 100644 index d0b2e35627..0000000000 --- a/test/e2e/broadcast_test.go +++ /dev/null @@ -1,167 +0,0 @@ -package e2e - -import ( - "context" - "math/big" - "testing" - "time" - - "github.com/0xPolygonHermez/zkevm-node/db" - "github.com/0xPolygonHermez/zkevm-node/event" - "github.com/0xPolygonHermez/zkevm-node/event/nileventstorage" - "github.com/0xPolygonHermez/zkevm-node/hex" - "github.com/0xPolygonHermez/zkevm-node/merkletree" - "github.com/0xPolygonHermez/zkevm-node/sequencer/broadcast" - "github.com/0xPolygonHermez/zkevm-node/sequencer/broadcast/pb" - "github.com/0xPolygonHermez/zkevm-node/state" - "github.com/0xPolygonHermez/zkevm-node/state/runtime/executor" - "github.com/0xPolygonHermez/zkevm-node/test/constants" - "github.com/0xPolygonHermez/zkevm-node/test/dbutils" - "github.com/0xPolygonHermez/zkevm-node/test/operations" - "github.com/0xPolygonHermez/zkevm-node/test/testutils" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/types" - "github.com/stretchr/testify/require" - "google.golang.org/protobuf/types/known/emptypb" -) - -const ( - serverAddress = "localhost:61090" - totalBatches = 2 - totalTxsLastBatch = 5 - forcedBatchNumber = 18 -) - -var ( - stateDBCfg = dbutils.NewStateConfigFromEnv() - ger = common.HexToHash("deadbeef") - mainnetExitRoot = common.HexToHash("caffe") - rollupExitRoot = common.HexToHash("bead") -) - -func TestBroadcast(t *testing.T) { - if testing.Short() { - t.Skip() - } - initOrResetDB() - ctx := context.Background() - - require.NoError(t, operations.StartComponent("network")) - require.NoError(t, operations.StartComponent("broadcast")) - defer func() { - require.NoError(t, operations.StopComponent("network")) - require.NoError(t, operations.StopComponent("broadcast")) - }() - st, err := initState() - require.NoError(t, err) - - require.NoError(t, populateDB(ctx, st)) - - client, conn, cancel, err := broadcast.NewClient(ctx, serverAddress) - require.NoError(t, err) - defer func() { - cancel() - require.NoError(t, conn.Close()) - }() - - lastBatch, err := client.GetLastBatch(ctx, &emptypb.Empty{}) - require.NoError(t, err) - require.Equal(t, totalBatches, int(lastBatch.BatchNumber)) - - batch, err := client.GetBatch(ctx, &pb.GetBatchRequest{ - BatchNumber: uint64(totalBatches), - }) - require.NoError(t, err) - require.Equal(t, totalBatches, int(batch.BatchNumber)) - - require.Equal(t, totalTxsLastBatch, len(batch.Transactions)) - require.EqualValues(t, forcedBatchNumber, batch.ForcedBatchNumber) - - require.Equal(t, mainnetExitRoot.String(), batch.MainnetExitRoot) - require.Equal(t, rollupExitRoot.String(), batch.RollupExitRoot) -} - -func initState() (*state.State, error) { - ctx := context.Background() - initOrResetDB() - sqlDB, err := db.NewSQLDB(stateDBCfg) - if err != nil { - return nil, err - } - stateDb := state.NewPostgresStorage(sqlDB) - executorUri := testutils.GetEnv(constants.ENV_ZKPROVER_URI, "localhost:50071") - merkleTreeUri := testutils.GetEnv(constants.ENV_MERKLETREE_URI, "localhost:50061") - executorClient, _, _ := executor.NewExecutorClient(ctx, executor.Config{URI: executorUri}) - mtDBClient, _, _ := merkletree.NewMTDBServiceClient(ctx, merkletree.Config{URI: merkleTreeUri}) - stateTree := merkletree.NewStateTree(mtDBClient) - - eventStorage, err := nileventstorage.NewNilEventStorage() - if err != nil { - return nil, err - } - eventLog := event.NewEventLog(event.Config{}, eventStorage) - - return state.NewState(state.Config{}, stateDb, executorClient, stateTree, eventLog), nil -} - -func populateDB(ctx context.Context, st *state.State) error { - const blockNumber = 1 - - var parentHash common.Hash - var l2Block types.Block - - const addBlock = "INSERT INTO state.block (block_num, received_at, block_hash) VALUES ($1, $2, $3)" - if _, err := st.PostgresStorage.Exec(ctx, addBlock, blockNumber, time.Now(), ""); err != nil { - return err - } - - const addForcedBatch = "INSERT INTO state.forced_batch (forced_batch_num, global_exit_root, raw_txs_data, coinbase, timestamp, block_num) VALUES ($1, $2, $3, $4, $5, $6)" - if _, err := st.PostgresStorage.Exec(ctx, addForcedBatch, forcedBatchNumber, ger.String(), "", common.HexToAddress("").String(), time.Now(), blockNumber); err != nil { - return err - } - - const addBatch = "INSERT INTO state.batch (batch_num, global_exit_root, timestamp, coinbase, local_exit_root, state_root, forced_batch_num) VALUES ($1, $2, $3, $4, $5, $6, $7)" - if _, err := st.PostgresStorage.Exec(ctx, addBatch, 1, ger.String(), time.Now(), common.HexToAddress("").String(), common.Hash{}.String(), common.Hash{}.String(), nil); err != nil { - return err - } - if _, err := st.PostgresStorage.Exec(ctx, addBatch, 2, ger.String(), time.Now(), common.HexToAddress("").String(), common.Hash{}.String(), common.Hash{}.String(), forcedBatchNumber); err != nil { - return err - } - - for i := 1; i <= totalTxsLastBatch; i++ { - if i == 1 { - parentHash = state.ZeroHash - } else { - parentHash = l2Block.Hash() - } - - // Store L2 Genesis Block - header := new(types.Header) - header.Number = new(big.Int).SetUint64(uint64(i - 1)) - header.ParentHash = parentHash - l2Block := types.NewBlockWithHeader(header) - l2Block.ReceivedAt = time.Now() - - if err := st.PostgresStorage.AddL2Block(ctx, totalBatches, l2Block, []*types.Receipt{}, nil); err != nil { - return err - } - - tx := types.NewTransaction(uint64(i), common.HexToAddress("0x1"), big.NewInt(0), uint64(0), nil, nil) - bData, _ := tx.MarshalBinary() - encoded := hex.EncodeToHex(bData) - const addTransaction = "INSERT INTO state.transaction (hash, encoded, l2_block_num) VALUES ($1, $2, $3)" - if _, err := st.PostgresStorage.Exec(ctx, addTransaction, tx.Hash().String(), encoded, l2Block.Number().Uint64()); err != nil { - return err - } - } - - const addExitRoots = "INSERT INTO state.exit_root (block_num, timestamp, global_exit_root, mainnet_exit_root, rollup_exit_root) VALUES ($1, $2, $3, $4, $5)" - _, err := st.PostgresStorage.Exec(ctx, addExitRoots, blockNumber, time.Now(), ger, mainnetExitRoot, rollupExitRoot) - return err -} - -func initOrResetDB() { - if err := dbutils.InitOrResetState(stateDBCfg); err != nil { - panic(err) - } -} diff --git a/test/e2e/permissionlessrpc_test.go b/test/e2e/permissionlessrpc_test.go index edb6bad289..ba5987b3f4 100644 --- a/test/e2e/permissionlessrpc_test.go +++ b/test/e2e/permissionlessrpc_test.go @@ -39,7 +39,7 @@ func TestPermissionlessJRPC(t *testing.T) { // Step 1: // - actions: send nTxsStep1 transactions to the trusted sequencer through the permissionless sequencer // first transaction gets the current nonce. The others are generated - // - assert: transactions are properly relayed, added in to the trusted state and broadcasted to the permissionless ndoe + // - assert: transactions are properly relayed, added in to the trusted state and broadcasted to the permissionless node nTxsStep1 := 10 // Load account with balance on local genesis