From db6e507ef8a675982b77900b6e6d4a58abf34b81 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Wed, 7 Aug 2024 14:43:19 +0100 Subject: [PATCH 01/11] Revert "refactor event log filtering for subscriptions (#1988)" (#2013) This reverts commit 81ad4043880316554d06e2b58cdd7472a2aa40e8. --- go/enclave/events/subscription_manager.go | 162 +++++++++++++++++++++- go/enclave/nodetype/common.go | 2 +- go/enclave/rpc/GetTransactionReceipt.go | 5 +- go/enclave/storage/enclavedb/events.go | 16 ++- go/enclave/storage/interfaces.go | 2 - go/enclave/storage/storage.go | 19 +-- 6 files changed, 171 insertions(+), 35 deletions(-) diff --git a/go/enclave/events/subscription_manager.go b/go/enclave/events/subscription_manager.go index 5641d09b62..27e6515d41 100644 --- a/go/enclave/events/subscription_manager.go +++ b/go/enclave/events/subscription_manager.go @@ -11,15 +11,24 @@ import ( "github.com/ten-protocol/go-ten/go/enclave/vkhandler" gethrpc "github.com/ten-protocol/go-ten/lib/gethfork/rpc" + "github.com/ten-protocol/go-ten/go/common/log" + "github.com/ten-protocol/go-ten/go/enclave/core" "github.com/ten-protocol/go-ten/go/enclave/storage" + gethcommon "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" gethlog "github.com/ethereum/go-ethereum/log" "github.com/ten-protocol/go-ten/go/common" ) +const ( + // The leading zero bytes in a hash indicating that it is possibly an address, since it only has 20 bytes of data. + zeroBytesHex = "000000000000000000000000" +) + type logSubscription struct { Subscription *common.LogSubscription // Handles the viewing key encryption @@ -83,6 +92,24 @@ func (s *SubscriptionManager) RemoveSubscription(id gethrpc.ID) { delete(s.subscriptions, id) } +// FilterLogsForReceipt removes the logs that the sender of a transaction is not allowed to view +func FilterLogsForReceipt(ctx context.Context, receipt *types.Receipt, account *gethcommon.Address, registry components.BatchRegistry) ([]*types.Log, error) { + var filteredLogs []*types.Log + stateDB, err := registry.GetBatchState(ctx, &receipt.BlockHash) + if err != nil { + return nil, fmt.Errorf("could not create state DB to filter logs. Cause: %w", err) + } + + for _, logItem := range receipt.Logs { + userAddrs := getUserAddrsFromLogTopics(logItem, stateDB) + if isRelevant(account, userAddrs) { + filteredLogs = append(filteredLogs, logItem) + } + } + + return filteredLogs, nil +} + // GetSubscribedLogsForBatch - Retrieves and encrypts the logs for the batch in live mode. // The assumption is that this function is called synchronously after the batch is produced func (s *SubscriptionManager) GetSubscribedLogsForBatch(ctx context.Context, batch *core.Batch, receipts types.Receipts) (common.EncryptedSubscriptionLogs, error) { @@ -94,17 +121,47 @@ func (s *SubscriptionManager) GetSubscribedLogsForBatch(ctx context.Context, bat return nil, nil } - h := batch.Hash() relevantLogsPerSubscription := map[gethrpc.ID][]*types.Log{} - if len(receipts) == 0 { + // extract the logs from all receipts + var allLogs []*types.Log + for _, receipt := range receipts { + allLogs = append(allLogs, receipt.Logs...) + } + + if len(allLogs) == 0 { return nil, nil } + // the stateDb is needed to extract the user addresses from the topics + h := batch.Hash() + stateDB, err := s.registry.GetBatchState(ctx, &h) + if err != nil { + return nil, fmt.Errorf("could not create state DB to filter logs. Cause: %w", err) + } + + // cache for the user addresses extracted from the individual logs + // this is an expensive operation so we are doing it lazy, and caching the result + userAddrsForLog := map[*types.Log][]*gethcommon.Address{} + for id, sub := range s.subscriptions { - relevantLogsForSub, err := s.storage.FilterLogs(ctx, sub.ViewingKeyEncryptor.AccountAddress, nil, nil, &h, sub.Subscription.Filter.Addresses, sub.Subscription.Filter.Topics) - if err != nil { - return nil, err + // first filter the logs + filteredLogs := filterLogs(allLogs, sub.Subscription.Filter.FromBlock, sub.Subscription.Filter.ToBlock, sub.Subscription.Filter.Addresses, sub.Subscription.Filter.Topics, s.logger) + + // the account requesting the logs is retrieved from the Viewing Key + requestingAccount := sub.ViewingKeyEncryptor.AccountAddress + relevantLogsForSub := []*types.Log{} + for _, logItem := range filteredLogs { + userAddrs, f := userAddrsForLog[logItem] + if !f { + userAddrs = getUserAddrsFromLogTopics(logItem, stateDB) + userAddrsForLog[logItem] = userAddrs + } + relevant := isRelevant(requestingAccount, userAddrs) + if relevant { + relevantLogsForSub = append(relevantLogsForSub, logItem) + } + s.logger.Debug("Subscription", log.SubIDKey, id, "acc", requestingAccount, "log", logItem, "extr_addr", userAddrs, "relev", relevant) } if len(relevantLogsForSub) > 0 { relevantLogsPerSubscription[id] = relevantLogsForSub @@ -115,6 +172,19 @@ func (s *SubscriptionManager) GetSubscribedLogsForBatch(ctx context.Context, bat return s.encryptLogs(relevantLogsPerSubscription) } +func isRelevant(sub *gethcommon.Address, userAddrs []*gethcommon.Address) bool { + // If there are no user addresses, this is a lifecycle event, and is therefore relevant to everyone. + if len(userAddrs) == 0 { + return true + } + for _, addr := range userAddrs { + if *addr == *sub { + return true + } + } + return false +} + // Encrypts each log with the appropriate viewing key. func (s *SubscriptionManager) encryptLogs(logsByID map[gethrpc.ID][]*types.Log) (map[gethrpc.ID][]byte, error) { encryptedLogsByID := map[gethrpc.ID][]byte{} @@ -140,3 +210,85 @@ func (s *SubscriptionManager) encryptLogs(logsByID map[gethrpc.ID][]*types.Log) return encryptedLogsByID, nil } + +// Of the log's topics, returns those that are (potentially) user addresses. A topic is considered a user address if: +// - It has 12 leading zero bytes (since addresses are 20 bytes long, while hashes are 32) +// - It has a non-zero nonce (to prevent accidental or malicious creation of the address matching a given topic, +// forcing its events to become permanently private +// - It does not have associated code (meaning it's a smart-contract address) +func getUserAddrsFromLogTopics(log *types.Log, db *state.StateDB) []*gethcommon.Address { + var userAddrs []*gethcommon.Address + + // We skip over the first topic, which is always the hash of the event. + for _, topic := range log.Topics[1:len(log.Topics)] { + if topic.Hex()[2:len(zeroBytesHex)+2] != zeroBytesHex { + continue + } + + potentialAddr := gethcommon.BytesToAddress(topic.Bytes()) + + // A user address must have a non-zero nonce. This prevents accidental or malicious sending of funds to an + // address matching a topic, forcing its events to become permanently private. + if db.GetNonce(potentialAddr) != 0 { + // If the address has code, it's a smart contract address instead. + if db.GetCode(potentialAddr) == nil { + userAddrs = append(userAddrs, &potentialAddr) + } + } + } + + return userAddrs +} + +// Lifted from eth/filters/filter.go in the go-ethereum repository. +// filterLogs creates a slice of logs matching the given criteria. +func filterLogs(logs []*types.Log, fromBlock, toBlock *gethrpc.BlockNumber, addresses []gethcommon.Address, topics [][]gethcommon.Hash, logger gethlog.Logger) []*types.Log { //nolint:gocognit + var ret []*types.Log +Logs: + for _, logItem := range logs { + if fromBlock != nil && fromBlock.Int64() >= 0 && fromBlock.Int64() > int64(logItem.BlockNumber) { + logger.Debug("Skipping log ", "log", logItem, "reason", "In the past. The starting block num for filter is bigger than log") + continue + } + if toBlock != nil && toBlock.Int64() > 0 && toBlock.Int64() < int64(logItem.BlockNumber) { + logger.Debug("Skipping log ", "log", logItem, "reason", "In the future. The ending block num for filter is smaller than log") + continue + } + + if len(addresses) > 0 && !includes(addresses, logItem.Address) { + logger.Debug("Skipping log ", "log", logItem, "reason", "The contract address of the log is not an address of interest") + continue + } + // If the to filtered topics is greater than the amount of topics in logs, skip. + if len(topics) > len(logItem.Topics) { + logger.Debug("Skipping log ", "log", logItem, "reason", "Insufficient topics. The log has less topics than the required one to satisfy the query") + continue + } + for i, sub := range topics { + match := len(sub) == 0 // empty rule set == wildcard + for _, topic := range sub { + if logItem.Topics[i] == topic { + match = true + break + } + } + if !match { + logger.Debug("Skipping log ", "log", logItem, "reason", "Topics do not match.") + continue Logs + } + } + ret = append(ret, logItem) + } + return ret +} + +// Lifted from eth/filters/filter.go in the go-ethereum repository. +func includes(addresses []gethcommon.Address, a gethcommon.Address) bool { + for _, addr := range addresses { + if addr == a { + return true + } + } + + return false +} diff --git a/go/enclave/nodetype/common.go b/go/enclave/nodetype/common.go index c414f63c81..bff4a94447 100644 --- a/go/enclave/nodetype/common.go +++ b/go/enclave/nodetype/common.go @@ -20,7 +20,7 @@ func ExportCrossChainData(ctx context.Context, storage storage.Storage, fromSeqN return nil, errutil.ErrCrossChainBundleNoBatches } - // todo - siliev - all those fetches need to be atomic + //todo - siliev - all those fetches need to be atomic header, err := storage.FetchHeadBatchHeader(ctx) if err != nil { return nil, err diff --git a/go/enclave/rpc/GetTransactionReceipt.go b/go/enclave/rpc/GetTransactionReceipt.go index 6eb4d2ae79..88c55f967d 100644 --- a/go/enclave/rpc/GetTransactionReceipt.go +++ b/go/enclave/rpc/GetTransactionReceipt.go @@ -14,6 +14,7 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ten-protocol/go-ten/go/common/errutil" "github.com/ten-protocol/go-ten/go/common/log" + "github.com/ten-protocol/go-ten/go/enclave/events" ) func GetTransactionReceiptValidate(reqParams []any, builder *CallBuilder[gethcommon.Hash, map[string]interface{}], _ *EncryptionManager) error { @@ -72,8 +73,8 @@ func GetTransactionReceiptExecute(builder *CallBuilder[gethcommon.Hash, map[stri return fmt.Errorf("could not retrieve transaction receipt in eth_getTransactionReceipt request. Cause: %w", err) } - // We only keep the logs that the requester is allowed to see - txReceipt.Logs, err = rpc.storage.FilterLogsForReceipt(builder.ctx, &txSigner, txReceipt.TxHash) + // We filter out irrelevant logs. + txReceipt.Logs, err = events.FilterLogsForReceipt(builder.ctx, txReceipt, &txSigner, rpc.registry) if err != nil { rpc.logger.Error("error filter logs ", log.TxKey, txHash, log.ErrKey, err) // this is a system error diff --git a/go/enclave/storage/enclavedb/events.go b/go/enclave/storage/enclavedb/events.go index 3bb0a8519f..f5a505bbc8 100644 --- a/go/enclave/storage/enclavedb/events.go +++ b/go/enclave/storage/enclavedb/events.go @@ -89,15 +89,17 @@ func WriteEventLog(ctx context.Context, dbTX *sql.Tx, eventTypeId uint64, userTo return err } -func FilterLogs(ctx context.Context, db *sql.DB, requestingAccount *gethcommon.Address, fromBlock, toBlock *big.Int, batchHash *common.L2BatchHash, addresses []gethcommon.Address, topics [][]gethcommon.Hash, txHash *gethcommon.Hash) ([]*types.Log, error) { +func FilterLogs( + ctx context.Context, + db *sql.DB, + requestingAccount *gethcommon.Address, + fromBlock, toBlock *big.Int, + batchHash *common.L2BatchHash, + addresses []gethcommon.Address, + topics [][]gethcommon.Hash, +) ([]*types.Log, error) { queryParams := []any{} query := "" - - if txHash != nil { - query += " AND tx.hash = ? " - queryParams = append(queryParams, txHash.Bytes()) - } - if batchHash != nil { query += " AND b.hash = ? " queryParams = append(queryParams, batchHash.Bytes()) diff --git a/go/enclave/storage/interfaces.go b/go/enclave/storage/interfaces.go index ac650b3107..fb7ac7b73a 100644 --- a/go/enclave/storage/interfaces.go +++ b/go/enclave/storage/interfaces.go @@ -141,8 +141,6 @@ type Storage interface { // the blockHash should always be nil. FilterLogs(ctx context.Context, requestingAccount *gethcommon.Address, fromBlock, toBlock *big.Int, blockHash *common.L2BatchHash, addresses []gethcommon.Address, topics [][]gethcommon.Hash) ([]*types.Log, error) - FilterLogsForReceipt(ctx context.Context, requestingAccount *gethcommon.Address, TxHash gethcommon.Hash) ([]*types.Log, error) - // DebugGetLogs returns logs for a given tx hash without any constraints - should only be used for debug purposes DebugGetLogs(ctx context.Context, txHash common.TxHash) ([]*tracers.DebugLogs, error) diff --git a/go/enclave/storage/storage.go b/go/enclave/storage/storage.go index 947d982fb0..244ffd7c5d 100644 --- a/go/enclave/storage/storage.go +++ b/go/enclave/storage/storage.go @@ -741,23 +741,6 @@ func (s *storageImpl) DebugGetLogs(ctx context.Context, txHash common.TxHash) ([ return enclavedb.DebugGetLogs(ctx, s.db.GetSQLDB(), txHash) } -func (s *storageImpl) FilterLogsForReceipt(ctx context.Context, requestingAccount *gethcommon.Address, txHash gethcommon.Hash) ([]*types.Log, error) { - defer s.logDuration("FilterLogs", measure.NewStopwatch()) - logs, err := enclavedb.FilterLogs(ctx, s.db.GetSQLDB(), requestingAccount, nil, nil, nil, nil, nil, &txHash) - if err != nil { - return nil, err - } - // the database returns an unsorted list of event logs. - // we have to perform the sorting programatically - sort.Slice(logs, func(i, j int) bool { - if logs[i].BlockNumber == logs[j].BlockNumber { - return logs[i].Index < logs[j].Index - } - return logs[i].BlockNumber < logs[j].BlockNumber - }) - return logs, nil -} - func (s *storageImpl) FilterLogs( ctx context.Context, requestingAccount *gethcommon.Address, @@ -767,7 +750,7 @@ func (s *storageImpl) FilterLogs( topics [][]gethcommon.Hash, ) ([]*types.Log, error) { defer s.logDuration("FilterLogs", measure.NewStopwatch()) - logs, err := enclavedb.FilterLogs(ctx, s.db.GetSQLDB(), requestingAccount, fromBlock, toBlock, blockHash, addresses, topics, nil) + logs, err := enclavedb.FilterLogs(ctx, s.db.GetSQLDB(), requestingAccount, fromBlock, toBlock, blockHash, addresses, topics) if err != nil { return nil, err } From d32dfda7fbc5d042b0077d53b8161d682c262394 Mon Sep 17 00:00:00 2001 From: Moray Grieve Date: Thu, 8 Aug 2024 09:38:08 +0100 Subject: [PATCH 02/11] Change log for v0.26 (#2011) * Change log * More changes --- changelog.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/changelog.md b/changelog.md index 74d014ee4b..5cccebdc59 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,33 @@ --- # Ten Testnet Change Log +# August 2024-08-08 (v0.26.0) +* This is an L2 deployment release meaning state will be lost in order to upgrade the network. The release + predominantly fixes known minor issues in the network, including issues deploying and interacting + with contracts using ethers6, and extracting event logs from tx receipts for bridge operations. +* A full list of the PRs merged in this release is as below; + * `db6e507e` Revert refactor event log filtering for subscriptions (#2013) + * `b043708a` Initiate bridge deployment (#2012) + * `475b7057` Disable rate limiting on local testnet (#2005) + * `86418f6d` Stopped returning errors on republish. (#2008) + * `396c113d` Only configure docker autorestart on the main containers (#2007) + * `e30e4eaa` Filter out irrelevant l1 txs, before sending into the enclave (#2006) + * `7b62b2e4` Revert message address indexing (#2002) + * `65d96465` Add dummy fields to keep ethers6 happy (#2003) + * `c3ad0a44` Fix for dependency (#2000) + * `3f7f12f9` Implement mock maxpriorityfeepergas (#1999) + * `9e91e5c2` Add ten headers (#1998) + * `ad61bdb0` Gateway rate limiting (#1942) + * `9bd08a23` Fix getblock rpc (#1997) + * `ec5315b6` Personal transaction/contract deployment details page (#1990) + * `97792e4e` Getstorageat with whitelist for proxies deployment (#1987) + * `e9b29779` Allow cors all origins to fix firefox error (#1991) + * `b13272b3` Replace custom query with personal transactions (#1986) + * `81ad4043` Refactor event log filtering for subscriptions (#1988) + * `6a4bc5b9` Fix event sql query (#1984) + * `a3a901bf` Frontend updates (#1932) + * `3b75a255` Block binding fix (#1982) + # July 2024-07-03 (v0.25.0) * This is an L2 deployment release meaning state will be lost in order to upgrade the network. Any dApps on the network will need to be redeployed. The release predominantly addresses performance improvements for large numbers From 3846fa56e5110c7a3c15a7543a6831db84df956c Mon Sep 17 00:00:00 2001 From: badgersrus <43809877+badgersrus@users.noreply.github.com> Date: Thu, 8 Aug 2024 10:58:25 +0200 Subject: [PATCH 03/11] Upgrade local Geth version to PoS (#1950) * Upgrade geth to 1.14.6 and prysm to 5.0.4 for a PoS dev network --- .github/workflows/build-pr.yml | 21 +- .../workflows/manual-deploy-testnet-l1.yml | 4 +- contracts/package.json | 2 +- go/common/host/host.go | 4 +- go/common/query_types.go | 2 +- go/config/enclave_cli_flags.go | 6 +- go/config/enclave_config.go | 6 +- go/config/enclave_config_test.go | 4 +- go/enclave/container/enclave_container.go | 2 +- go/host/container/host_container.go | 2 +- go/host/host.go | 4 +- ...lient_api_obscuro.go => client_api_ten.go} | 26 +- go/node/config.go | 10 +- go/node/docker_node.go | 2 +- go/obsclient/obsclient.go | 4 +- go/wallet/wallet.go | 6 - integration/common/constants.go | 2 +- integration/constants.go | 8 +- .../contract_deployer_test.go | 12 +- integration/eth2network/build_number.go | 44 ++ integration/eth2network/config.yml | 35 + integration/eth2network/eth2_binaries.go | 49 +- integration/eth2network/eth2_network.go | 649 ------------------ integration/eth2network/eth2_network_test.go | 183 ----- .../{eth2_configs.go => genesis-init.json} | 172 ++--- integration/eth2network/jwt.hex | 1 + integration/eth2network/main/cli.go | 71 +- integration/eth2network/main/main.go | 29 +- integration/eth2network/password.txt | 0 integration/eth2network/pk.txt | 1 + integration/eth2network/pos_eth2_network.go | 388 +++++++++++ .../eth2network/pos_eth2_network_test.go | 160 +++++ integration/eth2network/rotation_writer.go | 122 ---- .../eth2network/rotation_writer_test.go | 37 - integration/eth2network/start-pos-network.sh | 150 ++++ integration/noderunner/noderunner_test.go | 55 +- .../simulation/devnetwork/dev_network.go | 16 +- integration/simulation/devnetwork/geth_l1.go | 4 +- .../simulation/network/geth_network.go | 17 +- integration/simulation/network/geth_utils.go | 56 +- integration/simulation/network/inmemory.go | 28 +- integration/simulation/network/network.go | 20 +- .../simulation/network/network_utils.go | 4 +- .../simulation/network/obscuro_node_utils.go | 38 +- integration/simulation/network/socket.go | 29 +- integration/simulation/output_stats.go | 10 +- .../simulation/p2p/in_mem_obscuro_client.go | 60 +- integration/simulation/simulation.go | 38 +- .../simulation_full_network_test.go | 4 +- .../simulation/transaction_injector.go | 40 +- integration/simulation/validate_chain.go | 65 +- integration/smartcontract/debug_wallet.go | 2 +- .../smartcontract/smartcontracts_test.go | 32 +- .../errors_contract.go | 2 +- .../events_contract.go | 2 +- .../gateway_user.go | 2 +- .../{obscurogateway => tengateway}/json.go | 2 +- .../tengateway_test.go | 23 +- integration/tenscan/tenscan_test.go | 26 +- testnet/eth2network.Dockerfile | 4 +- testnet/launcher/docker.go | 8 +- testnet/launcher/eth2network/docker.go | 3 +- testnet/testnet-local-eth2network.sh | 1 - tools/hardhatdeployer/contract_deployer.go | 2 +- tools/tenscan/backend/obscuroscan_backend.go | 2 +- 65 files changed, 1240 insertions(+), 1573 deletions(-) rename go/host/rpc/clientapi/{client_api_obscuro.go => client_api_ten.go} (59%) create mode 100644 integration/eth2network/build_number.go create mode 100644 integration/eth2network/config.yml delete mode 100644 integration/eth2network/eth2_network.go delete mode 100644 integration/eth2network/eth2_network_test.go rename integration/eth2network/{eth2_configs.go => genesis-init.json} (69%) create mode 100644 integration/eth2network/jwt.hex create mode 100644 integration/eth2network/password.txt create mode 100644 integration/eth2network/pk.txt create mode 100644 integration/eth2network/pos_eth2_network.go create mode 100644 integration/eth2network/pos_eth2_network_test.go delete mode 100644 integration/eth2network/rotation_writer.go delete mode 100644 integration/eth2network/rotation_writer_test.go create mode 100755 integration/eth2network/start-pos-network.sh rename integration/{obscurogateway => tengateway}/errors_contract.go (99%) rename integration/{obscurogateway => tengateway}/events_contract.go (99%) rename integration/{obscurogateway => tengateway}/gateway_user.go (99%) rename integration/{obscurogateway => tengateway}/json.go (96%) rename integration/{obscurogateway => tengateway}/tengateway_test.go (98%) diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index 1bc3e8ea24..cfee96c260 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -20,6 +20,11 @@ jobs: with: go-version: 1.21.8 + # Set the initial build number environment variable + - name: Set Build Number + run: | + echo "BUILD_NUMBER=1" >> $GITHUB_ENV + # Makes sure the artifacts are built correctly - name: Build run: go build -v ./... @@ -31,19 +36,25 @@ jobs: # Close specified ports using lsof before testing / local port list compiled from ./integration/constants.go - name: Close Integration Test Ports run: | - killall -9 geth-v1.12.2 || true - killall -9 beacon-chain-v4.0.6 || true - killall -9 validator-v4.0.6 || true + killall -9 geth || true + killall -9 beacon || true + killall -9 validator || true lowest_port=8000 # Lowest starting port highest_port=58000 # Highest port considering the offset additional_ports=(80 81 99) # Additional specific ports - + # Find processes listening on ports within the range and kill them for pid in $(lsof -iTCP:$lowest_port-$highest_port -sTCP:LISTEN -t); do echo "Killing process $pid on one of the ports from $lowest_port to $highest_port" kill $pid || true done + + # Find processes listening on ports within the range and kill them + for pid in $(lsof -iUDP:$lowest_port-$highest_port -t); do + echo "Killing process $pid on one of the ports from $lowest_port to $highest_port" + kill $pid || true + done # Close additional specific ports for port in "${additional_ports[@]}"; do @@ -54,7 +65,7 @@ jobs: done - name: Test - run: go test --failfast -v ./... -count=1 -timeout 5m + run: go test --failfast -v ./... -count=1 -timeout 10m - name: Store simulation logs uses: actions/upload-artifact@v4 diff --git a/.github/workflows/manual-deploy-testnet-l1.yml b/.github/workflows/manual-deploy-testnet-l1.yml index b92101dff0..2ccace0ff1 100644 --- a/.github/workflows/manual-deploy-testnet-l1.yml +++ b/.github/workflows/manual-deploy-testnet-l1.yml @@ -130,7 +130,5 @@ jobs: && docker run -d \ -p 8025:8025 -p 8026:8026 -p 9000:9000 -p 9001:9001 \ --entrypoint /home/obscuro/go-obscuro/integration/eth2network/main/main ${{ vars.DOCKER_BUILD_TAG_ETH2NETWORK }} \ - --blockTimeSecs=15 --slotsPerEpoch=2 --slotsPerSecond=15 \ - --numNodes=1 --gethHTTPStartPort=8025 --gethWSStartPort=9000 \ - --logToFile=false \ + --gethHTTPStartPort=8025 --gethWSStartPort=9000 \ --prefundedAddrs="${{ vars.ACCOUNT_ADDR_WORKER }},${{ vars.ACCOUNT_ADDR_NODE_0 }},${{ vars.ACCOUNT_ADDR_NODE_1 }},${{ vars.ACCOUNT_ADDR_NODE_2 }},${{ vars.ACCOUNT_ADDR_L1_BRIDGE_TEST }}"' diff --git a/contracts/package.json b/contracts/package.json index 5ba922d48b..951a84f4e7 100644 --- a/contracts/package.json +++ b/contracts/package.json @@ -30,4 +30,4 @@ "peerDependencies": { "@nomicfoundation/hardhat-verify" : "2.0.8" } -} +} \ No newline at end of file diff --git a/go/common/host/host.go b/go/common/host/host.go index 1a49f0888d..c50855cccd 100644 --- a/go/common/host/host.go +++ b/go/common/host/host.go @@ -30,8 +30,8 @@ type Host interface { // HealthCheck returns the health status of the host + enclave + db HealthCheck(context.Context) (*HealthCheck, error) - // ObscuroConfig returns the info of the Obscuro network - ObscuroConfig() (*common.ObscuroNetworkInfo, error) + // TenConfig returns the info of the Obscuro network + TenConfig() (*common.TenNetworkInfo, error) // NewHeadsChan returns live batch headers // Note - do not use directly. This is meant only for the NewHeadsManager, which multiplexes the headers diff --git a/go/common/query_types.go b/go/common/query_types.go index 5a56fe9248..8d772df04b 100644 --- a/go/common/query_types.go +++ b/go/common/query_types.go @@ -110,7 +110,7 @@ func (p *QueryPagination) UnmarshalJSON(data []byte) error { return nil } -type ObscuroNetworkInfo struct { +type TenNetworkInfo struct { ManagementContractAddress common.Address L1StartHash common.Hash MessageBusAddress common.Address diff --git a/go/config/enclave_cli_flags.go b/go/config/enclave_cli_flags.go index b357aca3f4..d13fed0597 100644 --- a/go/config/enclave_cli_flags.go +++ b/go/config/enclave_cli_flags.go @@ -25,7 +25,7 @@ const ( ProfilerEnabledFlag = "profilerEnabled" MinGasPriceFlag = "minGasPrice" MessageBusAddressFlag = "messageBusAddress" - ObscuroGenesisFlag = "obscuroGenesis" + TenGenesisFlag = "tenGenesis" DebugNamespaceEnabledFlag = "debugNamespaceEnabled" MaxBatchSizeFlag = "maxBatchSize" MaxRollupSizeFlag = "maxRollupSize" @@ -55,7 +55,7 @@ var EnclaveFlags = map[string]*flag.TenFlag{ L2BaseFeeFlag: flag.NewUint64Flag(L2BaseFeeFlag, params.InitialBaseFee, ""), L2CoinbaseFlag: flag.NewStringFlag(L2CoinbaseFlag, "0xd6C9230053f45F873Cb66D8A02439380a37A4fbF", ""), GasBatchExecutionLimit: flag.NewUint64Flag(GasBatchExecutionLimit, 3_000_000_000, "Max gas that can be executed in a single batch"), - ObscuroGenesisFlag: flag.NewStringFlag(ObscuroGenesisFlag, "", "The json string with the obscuro genesis"), + TenGenesisFlag: flag.NewStringFlag(TenGenesisFlag, "", "The json string with the obscuro genesis"), L1ChainIDFlag: flag.NewInt64Flag(L1ChainIDFlag, 1337, "An integer representing the unique chain id of the Ethereum chain used as an L1 (default 1337)"), ObscuroChainIDFlag: flag.NewInt64Flag(ObscuroChainIDFlag, 443, "An integer representing the unique chain id of the Obscuro chain (default 443)"), UseInMemoryDBFlag: flag.NewBoolFlag(UseInMemoryDBFlag, true, "Whether the enclave will use an in-memory DB rather than persist data"), @@ -68,7 +68,7 @@ var EnclaveFlags = map[string]*flag.TenFlag{ var enclaveRestrictedFlags = []string{ L1ChainIDFlag, ObscuroChainIDFlag, - ObscuroGenesisFlag, + TenGenesisFlag, UseInMemoryDBFlag, ProfilerEnabledFlag, DebugNamespaceEnabledFlag, diff --git a/go/config/enclave_config.go b/go/config/enclave_config.go index ad1657fb47..fdeec56d00 100644 --- a/go/config/enclave_config.go +++ b/go/config/enclave_config.go @@ -54,8 +54,8 @@ type EnclaveConfig struct { MessageBusAddress gethcommon.Address // P2P address for validators to connect to the sequencer for live batch data SequencerP2PAddress string - // A json string that specifies the prefunded addresses at the genesis of the Obscuro network - ObscuroGenesis string + // A json string that specifies the prefunded addresses at the genesis of the Ten network + TenGenesis string // Whether debug calls are available DebugNamespaceEnabled bool // Maximum bytes a batch can be uncompressed. @@ -186,7 +186,7 @@ func newConfig(flags map[string]*flag.TenFlag) (*EnclaveConfig, error) { cfg.ProfilerEnabled = flags[ProfilerEnabledFlag].Bool() cfg.MinGasPrice = big.NewInt(flags[MinGasPriceFlag].Int64()) cfg.MessageBusAddress = gethcommon.HexToAddress(flags[MessageBusAddressFlag].String()) - cfg.ObscuroGenesis = flags[ObscuroGenesisFlag].String() + cfg.TenGenesis = flags[TenGenesisFlag].String() cfg.DebugNamespaceEnabled = flags[DebugNamespaceEnabledFlag].Bool() cfg.MaxBatchSize = flags[MaxBatchSizeFlag].Uint64() cfg.MaxRollupSize = flags[MaxRollupSizeFlag].Uint64() diff --git a/go/config/enclave_config_test.go b/go/config/enclave_config_test.go index c587572e91..801a1951ac 100644 --- a/go/config/enclave_config_test.go +++ b/go/config/enclave_config_test.go @@ -76,7 +76,7 @@ func TestRestrictedMode(t *testing.T) { t.Setenv("EDG_TESTMODE", "false") t.Setenv("EDG_"+strings.ToUpper(L1ChainIDFlag), "4444") t.Setenv("EDG_"+strings.ToUpper(ObscuroChainIDFlag), "1243") - t.Setenv("EDG_"+strings.ToUpper(ObscuroGenesisFlag), "{}") + t.Setenv("EDG_"+strings.ToUpper(TenGenesisFlag), "{}") t.Setenv("EDG_"+strings.ToUpper(UseInMemoryDBFlag), "true") t.Setenv("EDG_"+strings.ToUpper(ProfilerEnabledFlag), "true") t.Setenv("EDG_"+strings.ToUpper(DebugNamespaceEnabledFlag), "true") @@ -115,7 +115,7 @@ func TestRestrictedModeNoCLIDuplication(t *testing.T) { t.Setenv("EDG_TESTMODE", "false") t.Setenv("EDG_"+strings.ToUpper(L1ChainIDFlag), "4444") t.Setenv("EDG_"+strings.ToUpper(ObscuroChainIDFlag), "1243") - t.Setenv("EDG_"+strings.ToUpper(ObscuroGenesisFlag), "{}") + t.Setenv("EDG_"+strings.ToUpper(TenGenesisFlag), "{}") t.Setenv("EDG_"+strings.ToUpper(UseInMemoryDBFlag), "true") t.Setenv("EDG_"+strings.ToUpper(ProfilerEnabledFlag), "true") t.Setenv("EDG_"+strings.ToUpper(DebugNamespaceEnabledFlag), "true") diff --git a/go/enclave/container/enclave_container.go b/go/enclave/container/enclave_container.go index 010a1e152b..1dbccb3ea5 100644 --- a/go/enclave/container/enclave_container.go +++ b/go/enclave/container/enclave_container.go @@ -65,7 +65,7 @@ func NewEnclaveContainerWithLogger(config *config.EnclaveConfig, logger gethlog. config.GenesisJSON = []byte(hardcodedGenesisJSON) } - genesis, err := obscuroGenesis.New(config.ObscuroGenesis) + genesis, err := obscuroGenesis.New(config.TenGenesis) if err != nil { logger.Crit("unable to parse obscuro genesis", log.ErrKey, err) } diff --git a/go/host/container/host_container.go b/go/host/container/host_container.go index c42ffbe6d4..feeb7f7625 100644 --- a/go/host/container/host_container.go +++ b/go/host/container/host_container.go @@ -172,7 +172,7 @@ func NewHostContainer(cfg *config.HostConfig, services *host.ServicesRegistry, p rpcServer.RegisterAPIs([]rpc.API{ { Namespace: APINamespaceObscuro, - Service: clientapi.NewObscuroAPI(h), + Service: clientapi.NewTenAPI(h), }, { Namespace: APINamespaceEth, diff --git a/go/host/host.go b/go/host/host.go index 3d2dfa1f98..219a9185bf 100644 --- a/go/host/host.go +++ b/go/host/host.go @@ -235,7 +235,7 @@ func (h *host) HealthCheck(ctx context.Context) (*hostcommon.HealthCheck, error) } // ObscuroConfig returns info on the Obscuro network -func (h *host) ObscuroConfig() (*common.ObscuroNetworkInfo, error) { +func (h *host) TenConfig() (*common.TenNetworkInfo, error) { if h.l2MessageBusAddress == nil { publicCfg, err := h.EnclaveClient().EnclavePublicConfig(context.Background()) if err != nil { @@ -243,7 +243,7 @@ func (h *host) ObscuroConfig() (*common.ObscuroNetworkInfo, error) { } h.l2MessageBusAddress = &publicCfg.L2MessageBusAddress } - return &common.ObscuroNetworkInfo{ + return &common.TenNetworkInfo{ ManagementContractAddress: h.config.ManagementContractAddress, L1StartHash: h.config.L1StartHash, diff --git a/go/host/rpc/clientapi/client_api_obscuro.go b/go/host/rpc/clientapi/client_api_ten.go similarity index 59% rename from go/host/rpc/clientapi/client_api_obscuro.go rename to go/host/rpc/clientapi/client_api_ten.go index 64c969a313..ce664b6665 100644 --- a/go/host/rpc/clientapi/client_api_obscuro.go +++ b/go/host/rpc/clientapi/client_api_ten.go @@ -8,33 +8,33 @@ import ( "github.com/ten-protocol/go-ten/go/common/host" ) -// ObscuroAPI implements Obscuro-specific JSON RPC operations. -type ObscuroAPI struct { +// TenAPI implements Ten-specific JSON RPC operations. +type TenAPI struct { host host.Host } -func NewObscuroAPI(host host.Host) *ObscuroAPI { - return &ObscuroAPI{ +func NewTenAPI(host host.Host) *TenAPI { + return &TenAPI{ host: host, } } -// Health returns the health status of obscuro host + enclave + db -func (api *ObscuroAPI) Health(ctx context.Context) (*host.HealthCheck, error) { +// Health returns the health status of Ten host + enclave + db +func (api *TenAPI) Health(ctx context.Context) (*host.HealthCheck, error) { return api.host.HealthCheck(ctx) } -// Config returns the config status of obscuro host + enclave + db -func (api *ObscuroAPI) Config() (*ChecksumFormattedObscuroNetworkConfig, error) { - config, err := api.host.ObscuroConfig() +// Config returns the config status of Ten host + enclave + db +func (api *TenAPI) Config() (*ChecksumFormattedTenNetworkConfig, error) { + config, err := api.host.TenConfig() if err != nil { return nil, err } return checksumFormatted(config), nil } -// ChecksumFormattedObscuroNetworkConfig serialises the addresses as EIP55 checksum addresses. -type ChecksumFormattedObscuroNetworkConfig struct { +// ChecksumFormattedTenNetworkConfig serialises the addresses as EIP55 checksum addresses. +type ChecksumFormattedTenNetworkConfig struct { ManagementContractAddress gethcommon.AddressEIP55 L1StartHash gethcommon.Hash MessageBusAddress gethcommon.AddressEIP55 @@ -42,12 +42,12 @@ type ChecksumFormattedObscuroNetworkConfig struct { ImportantContracts map[string]gethcommon.AddressEIP55 // map of contract name to address } -func checksumFormatted(info *common.ObscuroNetworkInfo) *ChecksumFormattedObscuroNetworkConfig { +func checksumFormatted(info *common.TenNetworkInfo) *ChecksumFormattedTenNetworkConfig { importantContracts := make(map[string]gethcommon.AddressEIP55) for name, addr := range info.ImportantContracts { importantContracts[name] = gethcommon.AddressEIP55(addr) } - return &ChecksumFormattedObscuroNetworkConfig{ + return &ChecksumFormattedTenNetworkConfig{ ManagementContractAddress: gethcommon.AddressEIP55(info.ManagementContractAddress), L1StartHash: info.L1StartHash, MessageBusAddress: gethcommon.AddressEIP55(info.MessageBusAddress), diff --git a/go/node/config.go b/go/node/config.go index 8187bed389..5ad4103be9 100644 --- a/go/node/config.go +++ b/go/node/config.go @@ -55,7 +55,7 @@ type Config struct { maxBatchInterval string rollupInterval string l1ChainID int - obscuroGenesis string + tenGenesis string } func NewNodeConfig(opts ...Option) *Config { @@ -64,7 +64,7 @@ func NewNodeConfig(opts ...Option) *Config { maxBatchInterval: "1s", rollupInterval: "3s", l1ChainID: 1337, - obscuroGenesis: "{}", + tenGenesis: "{}", } for _, opt := range opts { @@ -90,7 +90,7 @@ func (c *Config) ToEnclaveConfig() *config.EnclaveConfig { cfg.LogLevel = c.logLevel cfg.Address = fmt.Sprintf("%s:%d", _localhost, c.enclaveWSPort) cfg.DebugNamespaceEnabled = c.debugNamespaceEnabled - cfg.ObscuroGenesis = c.obscuroGenesis + cfg.TenGenesis = c.tenGenesis if c.nodeType == "sequencer" && c.coinbaseAddress != "" { cfg.GasPaymentAddress = gethcommon.HexToAddress(c.coinbaseAddress) @@ -338,9 +338,9 @@ func WithL1ChainID(i int) Option { } } -func WithObscuroGenesis(g string) Option { +func WithTenGenesis(g string) Option { return func(c *Config) { - c.obscuroGenesis = g + c.tenGenesis = g } } diff --git a/go/node/docker_node.go b/go/node/docker_node.go index 48d750f7e9..78e96b80a1 100644 --- a/go/node/docker_node.go +++ b/go/node/docker_node.go @@ -176,7 +176,7 @@ func (d *DockerNode) startEnclave() error { "-maxBatchSize=56320", "-maxRollupSize=65536", fmt.Sprintf("-logLevel=%d", d.cfg.logLevel), - "-obscuroGenesis", "{}", + "-tenGenesis", "{}", "-edgelessDBHost", d.cfg.nodeName+"-edgelessdb", ) diff --git a/go/obsclient/obsclient.go b/go/obsclient/obsclient.go index 29bed17426..475f01aee0 100644 --- a/go/obsclient/obsclient.go +++ b/go/obsclient/obsclient.go @@ -252,8 +252,8 @@ func (oc *ObsClient) GetBatchTransactions(hash gethcommon.Hash) (*common.Transac } // GetConfig returns the network config for obscuro -func (oc *ObsClient) GetConfig() (*common.ObscuroNetworkInfo, error) { - var result common.ObscuroNetworkInfo +func (oc *ObsClient) GetConfig() (*common.TenNetworkInfo, error) { + var result common.TenNetworkInfo err := oc.rpcClient.Call(&result, rpc.Config) if err != nil { return nil, err diff --git a/go/wallet/wallet.go b/go/wallet/wallet.go index 6c6209cd29..c3dc1a2806 100644 --- a/go/wallet/wallet.go +++ b/go/wallet/wallet.go @@ -20,8 +20,6 @@ type Wallet interface { Address() common.Address // SignTransaction returns a signed transaction SignTransaction(tx types.TxData) (*types.Transaction, error) - SignTransactionForChainID(tx types.TxData, chainID *big.Int) (*types.Transaction, error) - // SetNonce overrides the current nonce // The GetTransactionCount is expected to be the next nonce to use in a transaction, not the current account GetTransactionCount SetNonce(nonce uint64) @@ -72,10 +70,6 @@ func (m *inMemoryWallet) SignTransaction(tx types.TxData) (*types.Transaction, e return types.SignNewTx(m.prvKey, types.NewCancunSigner(m.chainID), tx) } -func (m *inMemoryWallet) SignTransactionForChainID(tx types.TxData, chainID *big.Int) (*types.Transaction, error) { - return types.SignNewTx(m.prvKey, types.NewLondonSigner(chainID), tx) -} - // Address returns the current wallet address func (m *inMemoryWallet) Address() common.Address { return m.pubKeyAddr diff --git a/integration/common/constants.go b/integration/common/constants.go index d786d7b40e..a7ab617ca0 100644 --- a/integration/common/constants.go +++ b/integration/common/constants.go @@ -78,7 +78,7 @@ func DefaultEnclaveConfig() *config.EnclaveConfig { SqliteDBPath: "", ProfilerEnabled: false, MinGasPrice: big.NewInt(params.InitialBaseFee), - ObscuroGenesis: "", + TenGenesis: "", DebugNamespaceEnabled: false, MaxBatchSize: 1024 * 55, MaxRollupSize: 1024 * 64, diff --git a/integration/constants.go b/integration/constants.go index e6c73d8224..ace11bc1da 100644 --- a/integration/constants.go +++ b/integration/constants.go @@ -21,8 +21,9 @@ const ( DefaultGethWSPortOffset = 100 DefaultGethAUTHPortOffset = 200 DefaultGethNetworkPortOffset = 300 - DefaultPrysmHTTPPortOffset = 400 + DefaultGethHTTPPortOffset = 400 DefaultPrysmP2PPortOffset = 500 + DefaultPrysmRPCPortOffset = 550 DefaultHostP2pOffset = 600 // The default offset for the host P2p DefaultEnclaveOffset = 700 // The default offset between a Geth nodes port and the enclave ports. Used in Socket Simulations. DefaultHostRPCHTTPOffset = 800 // The default offset for the host's RPC HTTP port @@ -36,3 +37,8 @@ const ( EthereumChainID = 1337 TenChainID = 443 ) + +const ( + GethNodeAddress = "0x123463a4b065722e99115d6c222f267d9cabb524" + GethNodePK = "2e0834786285daccd064ca17f1654f67b4aef298acbb82cef9ec422fb4975622" +) diff --git a/integration/contractdeployer/contract_deployer_test.go b/integration/contractdeployer/contract_deployer_test.go index 5907f99595..95dcbf0198 100644 --- a/integration/contractdeployer/contract_deployer_test.go +++ b/integration/contractdeployer/contract_deployer_test.go @@ -47,7 +47,7 @@ func init() { //nolint:gochecknoinits func TestCanDeployLayer2ERC20Contract(t *testing.T) { startPort := integration.StartPortContractDeployerTest1 hostWSPort := startPort + integration.DefaultHostRPCWSOffset - createObscuroNetwork(t, startPort) + creatTenNetwork(t, startPort) // This sleep is required to ensure the initial rollup exists, and thus contract deployer can check its balance. time.Sleep(2 * time.Second) @@ -83,7 +83,7 @@ func TestCanDeployLayer2ERC20Contract(t *testing.T) { func TestFaucetSendsFundsOnlyIfNeeded(t *testing.T) { startPort := integration.StartPortContractDeployerTest2 hostWSPort := startPort + integration.DefaultHostRPCWSOffset - createObscuroNetwork(t, startPort) + creatTenNetwork(t, startPort) faucetWallet := wallet.NewInMemoryWalletFromConfig(genesis.TestnetPrefundedPK, integration.TenChainID, testlog.Logger()) faucetClient := getClient(hostWSPort, faucetWallet) @@ -130,7 +130,7 @@ func TestFaucetSendsFundsOnlyIfNeeded(t *testing.T) { } // Creates a single-node Obscuro network for testing. -func createObscuroNetwork(t *testing.T, startPort int) { +func creatTenNetwork(t *testing.T, startPort int) { // Create the Obscuro network. numberOfNodes := 1 wallets := params.NewSimWallets(1, numberOfNodes, integration.EthereumChainID, integration.TenChainID) @@ -144,9 +144,9 @@ func createObscuroNetwork(t *testing.T, startPort int) { WithPrefunding: true, } simStats := stats.NewStats(simParams.NumberOfNodes) - obscuroNetwork := network.NewNetworkOfSocketNodes(wallets) - t.Cleanup(obscuroNetwork.TearDown) - _, err := obscuroNetwork.Create(&simParams, simStats) + tenNetwork := network.NewNetworkOfSocketNodes(wallets) + t.Cleanup(tenNetwork.TearDown) + _, err := tenNetwork.Create(&simParams, simStats) if err != nil { panic(fmt.Sprintf("failed to create test Obscuro network. Cause: %s", err)) } diff --git a/integration/eth2network/build_number.go b/integration/eth2network/build_number.go new file mode 100644 index 0000000000..967db76fd5 --- /dev/null +++ b/integration/eth2network/build_number.go @@ -0,0 +1,44 @@ +package eth2network + +import ( + "fmt" + "os" + "path" + "strconv" +) + +// Need this due to character limit on unix path when deploying the geth network on azure and integration tests. We +// incremenet the build number up to 9999 and then reset to 1, overwriting any existing files. +func getBuildNumber() (int, error) { + buildNumberStr := os.Getenv("BUILD_NUMBER") + var buildNumber int + var err error + + if buildNumberStr == "" { + buildNumber = 1 + } else { + buildNumber, err = strconv.Atoi(buildNumberStr) + if err != nil { + return 0, fmt.Errorf("Error converting build number: %v\n", err) + } + } + + // increment the build number until an unused folder is found + for { + buildPath := path.Join(basepath, "../.build/eth2", strconv.Itoa(buildNumber)) + if _, err := os.Stat(buildPath); os.IsNotExist(err) { + break + } + buildNumber++ + if buildNumber > 9999 { + buildNumber = 1 + } + } + + err = os.Setenv("BUILD_NUMBER", strconv.Itoa(buildNumber)) + if err != nil { + return 0, fmt.Errorf("Error setting build number: %v\n", err) + } + + return buildNumber, nil +} diff --git a/integration/eth2network/config.yml b/integration/eth2network/config.yml new file mode 100644 index 0000000000..210e3c1ea4 --- /dev/null +++ b/integration/eth2network/config.yml @@ -0,0 +1,35 @@ +CONFIG_NAME: interop +PRESET_BASE: interop + +# Do not change +DEPOSIT_CHAIN_ID: 1337 +DEPOSIT_NETWORK_ID: 1337 + +# Genesis +GENESIS_FORK_VERSION: 0x20000089 + +# Altair +ALTAIR_FORK_EPOCH: 0 +ALTAIR_FORK_VERSION: 0x20000090 + +# Merge +BELLATRIX_FORK_EPOCH: 0 +BELLATRIX_FORK_VERSION: 0x20000091 +TERMINAL_TOTAL_DIFFICULTY: 0 + +# Capella +CAPELLA_FORK_EPOCH: 0 +CAPELLA_FORK_VERSION: 0x20000092 +MAX_WITHDRAWALS_PER_PAYLOAD: 16 + +DENEB_FORK_EPOCH: 0 +DENEB_FORK_VERSION: 0x20000093 + +ELECTRA_FORK_VERSION: 0x20000094 + +# Time parameters +SECONDS_PER_SLOT: 12 +SLOTS_PER_EPOCH: 6 + +# Deposit contract +DEPOSIT_CONTRACT_ADDRESS: 0x4242424242424242424242424242424242424242 \ No newline at end of file diff --git a/integration/eth2network/eth2_binaries.go b/integration/eth2network/eth2_binaries.go index eb8ffa10ab..cd7a4a7bed 100644 --- a/integration/eth2network/eth2_binaries.go +++ b/integration/eth2network/eth2_binaries.go @@ -17,8 +17,8 @@ import ( ) const ( - _gethVersion = "1.12.2-bed84606" - _prysmVersion = "v4.0.6" + _gethVersion = "1.14.6" + _prysmVersion = "v5.0.4" ) var ( @@ -29,6 +29,14 @@ var ( creationLock sync.Mutex // makes sure there isn't two creations running at the same time ) +var _gethFileNameVersion = fmt.Sprintf("geth-%s-%s-%s", runtime.GOOS, runtime.GOARCH, _gethVersion) + +var ( + _prysmBeaconChainFileNameVersion = fmt.Sprintf("beacon-chain-%s-%s-%s", _prysmVersion, runtime.GOOS, runtime.GOARCH) + _prysmCTLFileNameVersion = fmt.Sprintf("prysmctl-%s-%s-%s", _prysmVersion, runtime.GOOS, runtime.GOARCH) + _prysmValidatorFileNameVersion = fmt.Sprintf("validator-%s-%s-%s", _prysmVersion, runtime.GOOS, runtime.GOARCH) +) + // EnsureBinariesExist makes sure node binaries exist, returns the base path where binaries exist // Downloads any missing binaries func EnsureBinariesExist() (string, error) { @@ -67,25 +75,24 @@ func EnsureBinariesExist() (string, error) { }() go func() { defer wg.Done() - err := checkOrDownloadBinary(_gethFileNameVersion, fmt.Sprintf("https://gethstore.blob.core.windows.net/builds/%s.tar.gz", _gethFileNameVersion), true) - if err != nil { - // geth 1.12 is not available to download for the mac, so we have to build it - println("Cannot download geth binary. Compiling from source.") - gethScript := path.Join(basepath, "./build_geth_binary.sh") - - v := strings.Split(_gethVersion, "-") - cmd := exec.Command( - "bash", - gethScript, - fmt.Sprintf("%s=%s", "--version", "v"+v[0]), - fmt.Sprintf("%s=%s", "--output", path.Join(basepath, _eth2BinariesRelPath, _gethFileNameVersion)), - ) - cmd.Stderr = os.Stderr - - if out, err := cmd.Output(); err != nil { - fmt.Printf("%s\n", out) - panic(err) - } + expectedFilePath := path.Join(basepath, _eth2BinariesRelPath, _gethFileNameVersion) + if fileExists(expectedFilePath) { + return + } + gethScript := path.Join(basepath, "./build_geth_binary.sh") + + v := strings.Split(_gethVersion, "-") + cmd := exec.Command( + "bash", + gethScript, + fmt.Sprintf("%s=%s", "--version", "v"+v[0]), + fmt.Sprintf("%s=%s", "--output", path.Join(basepath, _eth2BinariesRelPath, _gethFileNameVersion)), + ) + cmd.Stderr = os.Stderr + + if out, err := cmd.Output(); err != nil { + fmt.Printf("%s\n", out) + panic(err) } }() diff --git a/integration/eth2network/eth2_network.go b/integration/eth2network/eth2_network.go deleted file mode 100644 index b3fdad4fcd..0000000000 --- a/integration/eth2network/eth2_network.go +++ /dev/null @@ -1,649 +0,0 @@ -package eth2network - -import ( - "context" - "encoding/json" - "fmt" - "io" - "net/http" - "os" - "os/exec" - "path" - "runtime" - "strconv" - "strings" - "time" - - "github.com/ten-protocol/go-ten/go/common/retry" - - "github.com/ethereum/go-ethereum/ethclient" - "github.com/ten-protocol/go-ten/integration/datagenerator" - "golang.org/x/sync/errgroup" - - gethcommon "github.com/ethereum/go-ethereum/common" -) - -const ( - _eth2BinariesRelPath = "../.build/eth2_bin" - _dataDirFlag = "--datadir" - _gethBinaryName = "geth" -) - -// https://gethstore.blob.core.windows.net/builds/geth-darwin-amd64-1.14.2-35b2d07f.tar.gz -var _gethFileNameVersion = fmt.Sprintf("geth-%s-%s-%s", runtime.GOOS, runtime.GOARCH, _gethVersion) - -// https://github.com/prysmaticlabs/prysm/releases/download/v4.0.6/ -var ( - _prysmBeaconChainFileNameVersion = fmt.Sprintf("beacon-chain-%s-%s-%s", _prysmVersion, runtime.GOOS, runtime.GOARCH) - _prysmCTLFileNameVersion = fmt.Sprintf("prysmctl-%s-%s-%s", _prysmVersion, runtime.GOOS, runtime.GOARCH) - _prysmValidatorFileNameVersion = fmt.Sprintf("validator-%s-%s-%s", _prysmVersion, runtime.GOOS, runtime.GOARCH) -) - -type Impl struct { - dataDirs []string - buildDir string - binDir string - gethBinaryPath string - prysmBinaryPath string - prysmBeaconBinaryPath string - gethGenesisPath string - prysmGenesisPath string - prysmConfigPath string - prysmValidatorBinaryPath string - chainID int - gethHTTPPorts []int - gethWSPorts []int - gethNetworkPorts []int - gethAuthRPCPorts []int - prysmBeaconHTTPPorts []int - prysmBeaconP2PPorts []int - gethProcesses []*exec.Cmd - prysmBeaconProcesses []*exec.Cmd - prysmValidatorProcesses []*exec.Cmd - gethLogFile io.Writer - prysmBeaconLogFile io.Writer - prysmValidtorLogFile io.Writer - preFundedMinerAddrs []string - preFundedMinerPKs []string - gethGenesisBytes []byte - timeout time.Duration -} - -type Eth2Network interface { - GethGenesis() []byte - Start() error - Stop() error -} - -func NewEth2Network( - binDir string, - logToFile bool, - gethHTTPPortStart int, - gethWSPortStart int, - gethAuthRPCPortStart int, - gethNetworkPortStart int, - prysmBeaconHTTPPortStart int, - prysmBeaconP2PPortStart int, - chainID int, - numNodes int, - blockTimeSecs int, - slotsPerEpoch int, - secondsPerSlot int, - preFundedAddrs []string, - timeout time.Duration, -) Eth2Network { - // Build dirs are suffixed with a timestamp so multiple executions don't collide - timestamp := strconv.FormatInt(time.Now().UnixMicro(), 10) - - // set the paths - buildDir := path.Join(basepath, "../.build/eth2", timestamp) - gethGenesisPath := path.Join(buildDir, "genesis.json") - prysmGenesisPath := path.Join(buildDir, "genesis.ssz") - prysmConfigPath := path.Join(buildDir, "prysm_chain_config.yml") - - gethBinaryPath := path.Join(binDir, _gethFileNameVersion, _gethBinaryName) - prysmBeaconBinaryPath := path.Join(binDir, _prysmBeaconChainFileNameVersion) - prysmBinaryPath := path.Join(binDir, _prysmCTLFileNameVersion) - prysmValidatorBinaryPath := path.Join(binDir, _prysmValidatorFileNameVersion) - - // catch any issues due to folder collision early - if _, err := os.Stat(buildDir); err == nil { - panic(fmt.Sprintf("folder %s already exists", buildDir)) - } - - // Nodes logs and execution related files are written in the build folder - err := os.MkdirAll(buildDir, os.ModePerm) - if err != nil { - panic(err) - } - - // Generate pk pairs for miners - preFundedMinerAddrs := make([]string, numNodes) - preFundedMinerPKs := make([]string, numNodes) - for i := 0; i < numNodes; i++ { - w := datagenerator.RandomWallet(int64(chainID)) - preFundedMinerAddrs[i] = w.Address().Hex() - preFundedMinerPKs[i] = fmt.Sprintf("%x", w.PrivateKey().D.Bytes()) - } - // Generate and write genesis file - genesisStr, err := generateGenesis(blockTimeSecs, chainID, preFundedMinerAddrs, append(preFundedAddrs, preFundedMinerAddrs...)) - if err != nil { - panic(err) - } - err = os.WriteFile(gethGenesisPath, []byte(genesisStr), 0o600) - if err != nil { - panic(err) - } - - // Write beacon config - beaconConf := fmt.Sprintf(_beaconConfig, chainID, chainID, secondsPerSlot, slotsPerEpoch) - err = os.WriteFile(prysmConfigPath, []byte(beaconConf), 0o600) - if err != nil { - panic(err) - } - - fmt.Printf("Geth nodes created in: %s\n", buildDir) - - gethProcesses := make([]*exec.Cmd, numNodes) - prysmBeaconProcesses := make([]*exec.Cmd, numNodes) - prysmValidatorProcesses := make([]*exec.Cmd, numNodes) - dataDirs := make([]string, numNodes) - gethHTTPPorts := make([]int, numNodes) - gethWSPorts := make([]int, numNodes) - gethAuthRPCPorts := make([]int, numNodes) - gethNetworkPorts := make([]int, numNodes) - prysmBeaconHTTPPorts := make([]int, numNodes) - prysmBeaconP2PPorts := make([]int, numNodes) - - for i := 0; i < numNodes; i++ { - dataDirs[i] = path.Join(buildDir, "n"+strconv.Itoa(i)) - gethHTTPPorts[i] = gethHTTPPortStart + i - gethWSPorts[i] = gethWSPortStart + i - gethAuthRPCPorts[i] = gethAuthRPCPortStart + i - gethNetworkPorts[i] = gethNetworkPortStart + i - prysmBeaconHTTPPorts[i] = prysmBeaconHTTPPortStart + i - prysmBeaconP2PPorts[i] = prysmBeaconP2PPortStart + i - } - - // create the log files - gethLogFile := io.Writer(os.Stdout) - prysmBeaconLogFile := io.Writer(os.Stdout) - prysmValidatorLogFile := io.Writer(os.Stdout) - - if logToFile { - gethLogFile, err = NewRotatingLogWriter(buildDir, "geth_logs", 10*1024*1024, 5) - if err != nil { - panic(err) - } - prysmBeaconLogFile, err = NewRotatingLogWriter(buildDir, "prysm_beacon_logs", 10*1024*1024, 5) - if err != nil { - panic(err) - } - prysmValidatorLogFile, err = NewRotatingLogWriter(buildDir, "prysm_validator_logs", 10*1024*1024, 5) - if err != nil { - panic(err) - } - } - - return &Impl{ - buildDir: buildDir, - binDir: binDir, - dataDirs: dataDirs, - chainID: chainID, - gethProcesses: gethProcesses, - prysmBeaconProcesses: prysmBeaconProcesses, - prysmValidatorProcesses: prysmValidatorProcesses, - gethHTTPPorts: gethHTTPPorts, - gethWSPorts: gethWSPorts, - gethNetworkPorts: gethNetworkPorts, - gethAuthRPCPorts: gethAuthRPCPorts, - prysmBeaconHTTPPorts: prysmBeaconHTTPPorts, - prysmBeaconP2PPorts: prysmBeaconP2PPorts, - gethBinaryPath: gethBinaryPath, - prysmBinaryPath: prysmBinaryPath, - prysmBeaconBinaryPath: prysmBeaconBinaryPath, - prysmConfigPath: prysmConfigPath, - prysmValidatorBinaryPath: prysmValidatorBinaryPath, - gethGenesisPath: gethGenesisPath, - prysmGenesisPath: prysmGenesisPath, - gethLogFile: gethLogFile, - prysmBeaconLogFile: prysmBeaconLogFile, - prysmValidtorLogFile: prysmValidatorLogFile, - preFundedMinerAddrs: preFundedMinerAddrs, - preFundedMinerPKs: preFundedMinerPKs, - gethGenesisBytes: []byte(genesisStr), - timeout: timeout, - } -} - -// Start starts the network -func (n *Impl) Start() error { - startTime := time.Now() - var eg errgroup.Group - - if err := n.ensureNoDuplicatedNetwork(); err != nil { - return err - } - - // initialize the genesis data on the nodes - for _, nodeDataDir := range n.dataDirs { - dataDir := nodeDataDir - eg.Go(func() error { - return n.gethInitGenesisData(dataDir) - }) - } - err := eg.Wait() - if err != nil { - return err - } - - // start each of the nodes - for i, nodeDataDir := range n.dataDirs { - dataDir := nodeDataDir - nodeID := i - go func() { - n.gethProcesses[nodeID], err = n.gethStartNode( - n.gethAuthRPCPorts[nodeID], - n.gethNetworkPorts[nodeID], - n.gethHTTPPorts[nodeID], - n.gethWSPorts[nodeID], - dataDir) - if err != nil { - panic(err) - } - time.Sleep(time.Second) - }() - } - - // wait for each of the nodes to start - for i := range n.dataDirs { - nodeID := i - eg.Go(func() error { - return n.waitForNodeUp(nodeID, time.Minute) - }) - } - err = eg.Wait() - if err != nil { - return err - } - - // link nodes together by providing the enodes (eth node address) of the other nodes - enodes := make([]string, len(n.dataDirs)) - for i := 0; i < len(n.dataDirs); i++ { - enodes[i], err = n.gethGetEnode(i) - if err != nil { - return err - } - } - err = n.gethImportEnodes(enodes) - if err != nil { - return err - } - - // import prefunded key to each node and start mining - for i := range n.dataDirs { - nodeID := i - eg.Go(func() error { - return n.gethImportMinerAccount(nodeID) - }) - } - err = eg.Wait() - if err != nil { - return err - } - - // generate the genesis using the node 0 - err = n.prysmGenerateGenesis() - if err != nil { - return err - } - - // start each of the beacon nodes - for i, nodeDataDir := range n.dataDirs { - nodeID := i - dataDir := nodeDataDir - go func() { - n.prysmBeaconProcesses[nodeID], err = n.prysmStartBeaconNode( - n.gethAuthRPCPorts[nodeID], - n.prysmBeaconHTTPPorts[nodeID], - n.prysmBeaconP2PPorts[nodeID], - dataDir, - ) - if err != nil { - panic(err) - } - }() - } - - time.Sleep(5 * time.Second) - // start each of the validator nodes - for i, nodeDataDir := range n.dataDirs { - nodeID := i - dataDir := nodeDataDir - go func() { - n.prysmValidatorProcesses[nodeID], err = n.prysmStartValidator(n.prysmBeaconHTTPPorts[nodeID], dataDir) - if err != nil { - panic(err) - } - }() - } - - // blocking wait until the network reaches the Merge - return n.waitForMergeEvent(startTime) -} - -// Stop stops the network -func (n *Impl) Stop() error { - for i := 0; i < len(n.dataDirs); i++ { - kill(n.gethProcesses[i].Process) - kill(n.prysmBeaconProcesses[i].Process) - kill(n.prysmValidatorProcesses[i].Process) - } - // wait a second for the kill signal - time.Sleep(time.Second) - return nil -} - -func kill(p *os.Process) { - killErr := p.Kill() - if killErr != nil { - fmt.Printf("Error killing process %s", killErr) - } - time.Sleep(200 * time.Millisecond) - err := p.Release() - if err != nil { - fmt.Printf("Error releasing process %s", err) - } -} - -// GethGenesis returns the Genesis used in geth to boot up the network -func (n *Impl) GethGenesis() []byte { - return n.gethGenesisBytes -} - -func (n *Impl) gethInitGenesisData(dataDirPath string) error { - // full command list at https://geth.ethereum.org/docs/fundamentals/command-line-options - args := []string{_dataDirFlag, dataDirPath, "init", n.gethGenesisPath} - fmt.Printf("gethInitGenesisData: %s %s\n", n.gethBinaryPath, strings.Join(args, " ")) - cmd := exec.Command(n.gethBinaryPath, args...) //nolint - cmd.Stdout = n.gethLogFile - cmd.Stderr = n.gethLogFile - - return cmd.Run() -} - -func (n *Impl) gethImportMinerAccount(nodeID int) error { - startScript := fmt.Sprintf(gethStartupScriptJS, n.preFundedMinerPKs[nodeID]) - - // full command list at https://geth.ethereum.org/docs/fundamentals/command-line-options - args := []string{ - "--exec", startScript, - "attach", fmt.Sprintf("http://127.0.0.1:%d", n.gethHTTPPorts[nodeID]), - } - - cmd := exec.Command(n.gethBinaryPath, args...) //nolint - cmd.Stdout = n.gethLogFile - cmd.Stderr = n.gethLogFile - - return cmd.Run() -} - -func (n *Impl) gethStartNode(executionPort, networkPort, httpPort, wsPort int, dataDirPath string) (*exec.Cmd, error) { - // full command list at https://geth.ethereum.org/docs/fundamentals/command-line-options - args := []string{ - _dataDirFlag, dataDirPath, - "--http", - "--http.addr", "0.0.0.0", - "--http.vhosts", "*", - "--http.port", fmt.Sprintf("%d", httpPort), - "--http.corsdomain", "*", - "--http.api", "admin,miner,engine,personal,eth,net,web3,debug", - "--ws", - "--ws.addr", "0.0.0.0", - "--ws.origins", "*", - "--ws.port", fmt.Sprintf("%d", wsPort), - "--ws.api", "admin,miner,engine,personal,eth,net,web3,debug", - "--authrpc.addr", "0.0.0.0", - "--authrpc.port", fmt.Sprintf("%d", executionPort), - "--authrpc.jwtsecret", path.Join(dataDirPath, "geth", "jwtsecret"), - "--port", fmt.Sprintf("%d", networkPort), - "--networkid", fmt.Sprintf("%d", n.chainID), - "--syncmode", "full", // sync mode to download and test all blocks and txs - "--allow-insecure-unlock", // allows to use personal accounts over http/ws - "--nodiscover", // don't try and discover peers - "--ipcdisable", // avoid geth erroring bc the ipc path is too long - "--verbosity", "1", // error log level - } - fmt.Printf("gethStartNode: %s %s\n", n.gethBinaryPath, strings.Join(args, " ")) - cmd := exec.Command(n.gethBinaryPath, args...) //nolint - cmd.Stdout = n.gethLogFile - cmd.Stderr = n.gethLogFile - - return cmd, cmd.Start() -} - -func (n *Impl) prysmGenerateGenesis() error { - // full command list at https://docs.prylabs.network/docs/prysm-usage/parameters - args := []string{ - "testnet", "generate-genesis", - "--num-validators", fmt.Sprintf("%d", len(n.dataDirs)), - "--output-ssz", n.prysmGenesisPath, - "--config-name", "interop", - "--chain-config-file", n.prysmConfigPath, - } - fmt.Printf("prysmGenerateGenesis: %s %s\n", n.prysmBinaryPath, strings.Join(args, " ")) - cmd := exec.Command(n.prysmBinaryPath, args...) //nolint - cmd.Stdout = n.prysmBeaconLogFile - cmd.Stderr = n.prysmBeaconLogFile - - return cmd.Run() -} - -func (n *Impl) prysmStartBeaconNode(gethAuthRPCPort, rpcPort, p2pPort int, nodeDataDir string) (*exec.Cmd, error) { - // full command list at https://docs.prylabs.network/docs/prysm-usage/parameters - args := []string{ - "--datadir", path.Join(nodeDataDir, "prysm", "beacondata"), - "--interop-eth1data-votes", - "--accept-terms-of-use", - "--no-discovery", - "--rpc-port", fmt.Sprintf("%d", rpcPort), - "--p2p-udp-port", fmt.Sprintf("%d", p2pPort), - "--min-sync-peers", fmt.Sprintf("%d", len(n.dataDirs)-1), - // if nodes have zero or one peers then that's the min-peers, if more than that then say 2 peers is the min - "--minimum-peers-per-subnet", fmt.Sprintf("%d", min(len(n.dataDirs)-1, 2)), - "--interop-num-validators", fmt.Sprintf("%d", len(n.dataDirs)), - "--genesis-state", n.prysmGenesisPath, - "--chain-config-file", n.prysmConfigPath, - "--config-file", n.prysmConfigPath, - "--chain-id", fmt.Sprintf("%d", n.chainID), - "--grpc-gateway-corsdomain", "*", - "--grpc-gateway-port", fmt.Sprintf("%d", rpcPort+10), - "--execution-endpoint", fmt.Sprintf("http://127.0.0.1:%d", gethAuthRPCPort), - "--jwt-secret", path.Join(nodeDataDir, "geth", "jwtsecret"), - "--contract-deployment-block", "0", - "--verbosity", "error", - } - - fmt.Printf("prysmStartBeaconNode: %s %s\n", n.prysmBeaconBinaryPath, strings.Join(args, " ")) - cmd := exec.Command(n.prysmBeaconBinaryPath, args...) //nolint - cmd.Stdout = n.prysmBeaconLogFile - cmd.Stderr = n.prysmBeaconLogFile - - return cmd, cmd.Start() -} - -func (n *Impl) prysmStartValidator(beaconHTTPPort int, nodeDataDir string) (*exec.Cmd, error) { - // full command list at https://docs.prylabs.network/docs/prysm-usage/parameters - args := []string{ - "--datadir", path.Join(nodeDataDir, "prysm", "validator"), - //"--beacon-rpc-gateway-provider", fmt.Sprintf("127.0.0.1:%d", prysmBeaconHTTPPort+10), - "--beacon-rpc-provider", fmt.Sprintf("127.0.0.1:%d", beaconHTTPPort), - "--interop-num-validators", fmt.Sprintf("%d", len(n.dataDirs)), - "--interop-start-index", "0", - "--chain-config-file", n.prysmConfigPath, - "--config-file", n.prysmConfigPath, - "--suggested-fee-recipient", "0x52FfeB84540173B15eEC5a486FdB5c769F50400a", // random address to avoid a continuous warning - "--force-clear-db", - "--disable-account-metrics", - "--accept-terms-of-use", - "--verbosity", "error", - } - - fmt.Printf("prysmStartValidator: %s %s\n", n.prysmValidatorBinaryPath, strings.Join(args, " ")) - cmd := exec.Command(n.prysmValidatorBinaryPath, args...) //nolint - cmd.Stdout = n.prysmValidtorLogFile - cmd.Stderr = n.prysmValidtorLogFile - - return cmd, cmd.Start() -} - -// waitForMergeEvent connects to the geth node and waits until block 2 (the merge block) is reached -func (n *Impl) waitForMergeEvent(startTime time.Time) error { - ctx := context.Background() - dial, err := ethclient.Dial(fmt.Sprintf("http://127.0.0.1:%d", n.gethHTTPPorts[0])) - if err != nil { - return err - } - number, err := dial.BlockNumber(ctx) - if err != nil { - return err - } - - // wait for the merge block - err = retry.Do( - func() error { - number, err = dial.BlockNumber(ctx) - if err != nil { - return err - } - if number <= 7 { - return fmt.Errorf("has not arrived at The Merge") - } - return nil - }, - retry.NewTimeoutStrategy(n.timeout, time.Second), - ) - if err != nil { - return err - } - - fmt.Printf("Reached the merge block after %s\n", time.Since(startTime)) - - if err = n.prefundedBalancesActive(dial); err != nil { - fmt.Printf("Error prefunding accounts %s\n", err.Error()) - return err - } - return nil -} - -// waitForNodeUp retries continuously for the node to respond to a http request -func (n *Impl) waitForNodeUp(nodeID int, timeout time.Duration) error { - for startTime := time.Now(); time.Now().Before(startTime.Add(timeout)); time.Sleep(time.Second) { - dial, err := ethclient.Dial(fmt.Sprintf("http://127.0.0.1:%d", n.gethHTTPPorts[nodeID])) - if err != nil { - continue - } - _, err = dial.BlockNumber(context.Background()) - if err == nil { - return nil - } - } - fmt.Printf("Geth node error:\n%s\n", n.gethProcesses[nodeID].Stderr) - return fmt.Errorf("node not responsive after %s", timeout) -} - -func (n *Impl) gethGetEnode(i int) (string, error) { - req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, - fmt.Sprintf("http://127.0.0.1:%d", n.gethHTTPPorts[i]), - strings.NewReader(`{"jsonrpc": "2.0", "method": "admin_nodeInfo", "params": [], "id": 1}`)) - if err != nil { - return "", err - } - req.Header.Set("Content-Type", "application/json; charset=UTF-8") - - client := &http.Client{} - response, err := client.Do(req) - if err != nil { - return "", err - } - defer response.Body.Close() - body, err := io.ReadAll(response.Body) - if err != nil { - return "", err - } - var res map[string]interface{} - err = json.Unmarshal(body, &res) - if err != nil { - return "", err - } - return res["result"].(map[string]interface{})["enode"].(string), nil -} - -func (n *Impl) gethImportEnodes(enodes []string) error { - for i, nodePort := range n.gethHTTPPorts { - for j, enode := range enodes { - if i == j { - continue // same node, node 0 does not need to know node 0 enode - } - - req, err := http.NewRequestWithContext( - context.Background(), - http.MethodPost, - fmt.Sprintf("http://127.0.0.1:%d", nodePort), - strings.NewReader( - fmt.Sprintf(`{"jsonrpc": "2.0", "method": "admin_addPeer", "params": ["%s"], "id": 1}`, enode), - ), - ) - if err != nil { - return err - } - - req.Header.Set("Content-Type", "application/json; charset=UTF-8") - - client := &http.Client{} - response, err := client.Do(req) - if err != nil { - return err - } - - err = response.Body.Close() - if err != nil { - return err - } - } - time.Sleep(time.Second) - } - return nil -} - -func (n *Impl) prefundedBalancesActive(client *ethclient.Client) error { - for _, addr := range n.preFundedMinerAddrs { - balance, err := client.BalanceAt(context.Background(), gethcommon.HexToAddress(addr), nil) - if err != nil { - return fmt.Errorf("unable to check balance for account %s - %w", addr, err) - } - if balance.Cmp(gethcommon.Big0) == 0 { - return fmt.Errorf("unexpected %s balance for account %s", balance.String(), addr) - } - fmt.Printf("Account %s prefunded with %s\n", addr, balance.String()) - } - - return nil -} - -func (n *Impl) ensureNoDuplicatedNetwork() error { - for nodeIdx, port := range n.gethWSPorts { - _, err := ethclient.Dial(fmt.Sprintf("ws://127.0.0.1:%d", port)) - if err == nil { - return fmt.Errorf("unexpected geth node %d is active before the network is started", nodeIdx) - } - } - return nil -} - -func min(a, b int) int { - if a < b { - return a - } - return b -} diff --git a/integration/eth2network/eth2_network_test.go b/integration/eth2network/eth2_network_test.go deleted file mode 100644 index 4eb712df21..0000000000 --- a/integration/eth2network/eth2_network_test.go +++ /dev/null @@ -1,183 +0,0 @@ -package eth2network - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "io" - "math/big" - "net/http" - "strings" - "testing" - "time" - - "github.com/ethereum/go-ethereum" - "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/ethclient" - "github.com/stretchr/testify/assert" - "github.com/ten-protocol/go-ten/go/common" - "github.com/ten-protocol/go-ten/go/ethadapter" - "github.com/ten-protocol/go-ten/go/wallet" - "github.com/ten-protocol/go-ten/integration" - "github.com/ten-protocol/go-ten/integration/datagenerator" - - gethcommon "github.com/ethereum/go-ethereum/common" - gethlog "github.com/ethereum/go-ethereum/log" -) - -const ( - _startPort = integration.StartPortEth2NetworkTests - // todo (@pedro) - ensure it works with more than 1 node - _numTestNodes = 1 -) - -func TestEnsureBinariesAreAvail(t *testing.T) { - path, err := EnsureBinariesExist() - assert.Nil(t, err) - t.Logf("Successfully downloaded files to %s", path) -} - -func TestStartEth2Network(t *testing.T) { - binDir, err := EnsureBinariesExist() - assert.Nil(t, err) - - chainID := int(datagenerator.RandomUInt64()) - randomWallets := make([]wallet.Wallet, _numTestNodes) - randomWalletAddrs := make([]string, _numTestNodes) - for i := 0; i < _numTestNodes; i++ { - randomWallets[i] = datagenerator.RandomWallet(int64(chainID)) - randomWalletAddrs[i] = randomWallets[i].Address().Hex() - } - - network := NewEth2Network( - binDir, - true, - _startPort, - _startPort+integration.DefaultGethWSPortOffset, - _startPort+integration.DefaultGethAUTHPortOffset, - _startPort+integration.DefaultGethNetworkPortOffset, - _startPort+integration.DefaultPrysmHTTPPortOffset, - _startPort+integration.DefaultPrysmP2PPortOffset, - chainID, - _numTestNodes, - 1, - 2, - 2, - randomWalletAddrs, - 2*time.Minute, - ) - // wait until the merge has happened - assert.Nil(t, network.Start()) - - defer network.Stop() //nolint: errcheck - - // test input configurations - t.Run("areConfigsUphold", func(t *testing.T) { - areConfigsUphold(t, randomWallets[0].Address(), chainID) - }) - - // test number of nodes - t.Run("numberOfNodes", func(t *testing.T) { - numberOfNodes(t) - }) - - // txs are minted - t.Run("txsAreMinted", func(t *testing.T) { - txsAreMinted(t, randomWallets) - }) -} - -func areConfigsUphold(t *testing.T, addr gethcommon.Address, chainID int) { - url := fmt.Sprintf("http://127.0.0.1:%d", _startPort) - conn, err := ethclient.Dial(url) - assert.Nil(t, err) - - at, err := conn.BalanceAt(context.Background(), addr, nil) - assert.Nil(t, err) - assert.True(t, at.Cmp(big.NewInt(1)) == 1) - - id, err := conn.NetworkID(context.Background()) - assert.Nil(t, err) - assert.Equal(t, int64(chainID), id.Int64()) -} - -func numberOfNodes(t *testing.T) { - for i := 0; i < _numTestNodes; i++ { - url := fmt.Sprintf("http://127.0.0.1:%d", _startPort+i) - - req, err := http.NewRequestWithContext( - context.Background(), - http.MethodPost, - url, - strings.NewReader(`{"jsonrpc": "2.0", "method": "net_peerCount", "params": [], "id": 1}`), - ) - assert.Nil(t, err) - req.Header.Set("Content-Type", "application/json; charset=UTF-8") - - client := &http.Client{} - response, err := client.Do(req) - assert.Nil(t, err) - - defer response.Body.Close() - body, err := io.ReadAll(response.Body) - assert.Nil(t, err) - - var res map[string]interface{} - err = json.Unmarshal(body, &res) - assert.Nil(t, err) - - err = json.Unmarshal(body, &res) - assert.Nil(t, err) - - assert.Equal(t, fmt.Sprintf("0x%x", _numTestNodes-1), res["result"]) - } -} - -func txsAreMinted(t *testing.T, wallets []wallet.Wallet) { - var err error - - ethclients := make([]ethadapter.EthClient, _numTestNodes) - for i := 0; i < _numTestNodes; i++ { - ethclients[i], err = ethadapter.NewEthClient("127.0.0.1", uint(_startPort+100+i), 30*time.Second, common.L2Address{}, gethlog.New()) - assert.Nil(t, err) - } - - for i := 0; i < _numTestNodes; i++ { - ethClient := ethclients[i] - w := wallets[i] - - toAddr := datagenerator.RandomAddress() - estimatedTx, err := ethClient.PrepareTransactionToSend(context.Background(), &types.LegacyTx{ - To: &toAddr, - Value: big.NewInt(100), - }, w.Address()) - assert.Nil(t, err) - - signedTx, err := w.SignTransaction(estimatedTx) - assert.Nil(t, err) - - err = ethClient.SendTransaction(signedTx) - assert.Nil(t, err) - - fmt.Printf("Created Tx: %s on node %d\n", signedTx.Hash().Hex(), i) - // make sure it's mined into a block within an acceptable time and avail in all nodes - for j := i; j < _numTestNodes; j++ { - fmt.Printf("Checking for tx receipt for %s on node %d\n", signedTx.Hash(), j) - var receipt *types.Receipt - for start := time.Now(); time.Since(start) < 30*time.Second; time.Sleep(time.Second) { - receipt, err = ethclients[j].TransactionReceipt(signedTx.Hash()) - if err == nil { - break - } - if !errors.Is(err, ethereum.NotFound) { - t.Fatal(err) - } - } - - if receipt == nil { - t.Fatalf("Did not mine the transaction after %s seconds in node %d - receipt: %+v", 30*time.Second, j, receipt) - } - } - } -} diff --git a/integration/eth2network/eth2_configs.go b/integration/eth2network/genesis-init.json similarity index 69% rename from integration/eth2network/eth2_configs.go rename to integration/eth2network/genesis-init.json index 8921fb97b4..6f244d60c8 100644 --- a/integration/eth2network/eth2_configs.go +++ b/integration/eth2network/genesis-init.json @@ -1,71 +1,9 @@ -package eth2network - -import ( - "encoding/json" - "fmt" - "strings" -) - -// -// These are base configurations to enable a clique network that after the merge block becomes a POS network -// Any change to these configurations should be done using a pattern similar to the generateGenesis method. -// - -const gethStartupScriptJS = ` -key = "%s"; -pwd = "password"; - -personal.importRawKey(key, pwd); -accts = personal.listAccounts; - -personal.unlockAccount(accts[0], pwd, 0); -console.log("Unlocked account"); -miner.setEtherbase(accts[0]); - -miner.start(); -console.log("Miner Started"); -` - -const _beaconConfig = ` -CONFIG_NAME: interop -PRESET_BASE: interop - -DEPOSIT_CHAIN_ID: %d -DEPOSIT_NETWORK_ID: %d - -# Genesis -GENESIS_FORK_VERSION: 0x20000089 - -# Altair -ALTAIR_FORK_EPOCH: 2 -ALTAIR_FORK_VERSION: 0x20000089 - -# Merge -BELLATRIX_FORK_EPOCH: 4 -BELLATRIX_FORK_VERSION: 0x20000089 -TERMINAL_TOTAL_DIFFICULTY: 10 - -# Capella -CAPELLA_FORK_EPOCH: 90000000000000000 -CAPELLA_FORK_VERSION: 0x20000089 - -# Time parameters -SECONDS_PER_SLOT: %d -SLOTS_PER_EPOCH: %d - -# Deposit contract -DEPOSIT_CONTRACT_ADDRESS: 0x4242424242424242424242424242424242424242 -` - -const _baseGenesis = `{ +{ "config": { - "ChainName": "l1_chain", - "chainId": 32382, - "consensus": "clique", + "chainId": 1337, "homesteadBlock": 0, "daoForkSupport": true, "eip150Block": 0, - "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000", "eip155Block": 0, "eip158Block": 0, "byzantiumBlock": 0, @@ -75,56 +13,66 @@ const _baseGenesis = `{ "muirGlacierBlock": 0, "berlinBlock": 0, "londonBlock": 0, - "terminalBlockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "arrowGlacierBlock": 0, "grayGlacierBlock": 0, - "clique": { - "period": 1, - "epoch": 1000 - }, - "terminalTotalDifficulty": 10 + "shanghaiTime": 1720522149, + "cancunTime": 1720522149, + "terminalTotalDifficulty": 0, + "terminalTotalDifficultyPassed": true }, - "difficulty": "1", - "gasLimit": "30000000", - "extradata": "0x0000000000000000000000000000000000000000000000000000000000000000123463a4B065722E99115D6c222f267d9cABb5240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "nonce": "0x0", + "timestamp": "0x668d15a5", + "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000123463a4b065722e99115d6c222f267d9cabb5240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "gasLimit": "0x1c9c380", + "difficulty": "0x1", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "coinbase": "0x0000000000000000000000000000000000000000", "alloc": { - "0x4242424242424242424242424242424242424242": { - "balance": "0", - "code": "0x60806040526004361061003f5760003560e01c806301ffc9a71461004457806322895118146100b6578063621fd130146101e3578063c5f2892f14610273575b600080fd5b34801561005057600080fd5b5061009c6004803603602081101561006757600080fd5b8101908080357bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916906020019092919050505061029e565b604051808215151515815260200191505060405180910390f35b6101e1600480360360808110156100cc57600080fd5b81019080803590602001906401000000008111156100e957600080fd5b8201836020820111156100fb57600080fd5b8035906020019184600183028401116401000000008311171561011d57600080fd5b90919293919293908035906020019064010000000081111561013e57600080fd5b82018360208201111561015057600080fd5b8035906020019184600183028401116401000000008311171561017257600080fd5b90919293919293908035906020019064010000000081111561019357600080fd5b8201836020820111156101a557600080fd5b803590602001918460018302840111640100000000831117156101c757600080fd5b909192939192939080359060200190929190505050610370565b005b3480156101ef57600080fd5b506101f8610fd0565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561023857808201518184015260208101905061021d565b50505050905090810190601f1680156102655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561027f57600080fd5b50610288610fe2565b6040518082815260200191505060405180910390f35b60007f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916148061036957507f85640907000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b9050919050565b603087879050146103cc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806116ec6026913960400191505060405180910390fd5b60208585905014610428576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260368152602001806116836036913960400191505060405180910390fd5b60608383905014610484576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602981526020018061175f6029913960400191505060405180910390fd5b670de0b6b3a76400003410156104e5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806117396026913960400191505060405180910390fd5b6000633b9aca0034816104f457fe5b061461054b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260338152602001806116b96033913960400191505060405180910390fd5b6000633b9aca00348161055a57fe5b04905067ffffffffffffffff80168111156105c0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260278152602001806117126027913960400191505060405180910390fd5b60606105cb82611314565b90507f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c589898989858a8a610600602054611314565b60405180806020018060200180602001806020018060200186810386528e8e82818152602001925080828437600081840152601f19601f82011690508083019250505086810385528c8c82818152602001925080828437600081840152601f19601f82011690508083019250505086810384528a818151815260200191508051906020019080838360005b838110156106a657808201518184015260208101905061068b565b50505050905090810190601f1680156106d35780820380516001836020036101000a031916815260200191505b508681038352898982818152602001925080828437600081840152601f19601f820116905080830192505050868103825287818151815260200191508051906020019080838360005b8381101561073757808201518184015260208101905061071c565b50505050905090810190601f1680156107645780820380516001836020036101000a031916815260200191505b509d505050505050505050505050505060405180910390a1600060028a8a600060801b6040516020018084848082843780830192505050826fffffffffffffffffffffffffffffffff19166fffffffffffffffffffffffffffffffff1916815260100193505050506040516020818303038152906040526040518082805190602001908083835b6020831061080e57805182526020820191506020810190506020830392506107eb565b6001836020036101000a038019825116818451168082178552505050505050905001915050602060405180830381855afa158015610850573d6000803e3d6000fd5b5050506040513d602081101561086557600080fd5b8101908080519060200190929190505050905060006002808888600090604092610891939291906115da565b6040516020018083838082843780830192505050925050506040516020818303038152906040526040518082805190602001908083835b602083106108eb57805182526020820191506020810190506020830392506108c8565b6001836020036101000a038019825116818451168082178552505050505050905001915050602060405180830381855afa15801561092d573d6000803e3d6000fd5b5050506040513d602081101561094257600080fd5b8101908080519060200190929190505050600289896040908092610968939291906115da565b6000801b604051602001808484808284378083019250505082815260200193505050506040516020818303038152906040526040518082805190602001908083835b602083106109cd57805182526020820191506020810190506020830392506109aa565b6001836020036101000a038019825116818451168082178552505050505050905001915050602060405180830381855afa158015610a0f573d6000803e3d6000fd5b5050506040513d6020811015610a2457600080fd5b810190808051906020019092919050505060405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b60208310610a8e5780518252602082019150602081019050602083039250610a6b565b6001836020036101000a038019825116818451168082178552505050505050905001915050602060405180830381855afa158015610ad0573d6000803e3d6000fd5b5050506040513d6020811015610ae557600080fd5b810190808051906020019092919050505090506000600280848c8c604051602001808481526020018383808284378083019250505093505050506040516020818303038152906040526040518082805190602001908083835b60208310610b615780518252602082019150602081019050602083039250610b3e565b6001836020036101000a038019825116818451168082178552505050505050905001915050602060405180830381855afa158015610ba3573d6000803e3d6000fd5b5050506040513d6020811015610bb857600080fd5b8101908080519060200190929190505050600286600060401b866040516020018084805190602001908083835b60208310610c085780518252602082019150602081019050602083039250610be5565b6001836020036101000a0380198251168184511680821785525050505050509050018367ffffffffffffffff191667ffffffffffffffff1916815260180182815260200193505050506040516020818303038152906040526040518082805190602001908083835b60208310610c935780518252602082019150602081019050602083039250610c70565b6001836020036101000a038019825116818451168082178552505050505050905001915050602060405180830381855afa158015610cd5573d6000803e3d6000fd5b5050506040513d6020811015610cea57600080fd5b810190808051906020019092919050505060405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b60208310610d545780518252602082019150602081019050602083039250610d31565b6001836020036101000a038019825116818451168082178552505050505050905001915050602060405180830381855afa158015610d96573d6000803e3d6000fd5b5050506040513d6020811015610dab57600080fd5b81019080805190602001909291905050509050858114610e16576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252605481526020018061162f6054913960600191505060405180910390fd5b6001602060020a0360205410610e77576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602181526020018061160e6021913960400191505060405180910390fd5b60016020600082825401925050819055506000602054905060008090505b6020811015610fb75760018083161415610ec8578260008260208110610eb757fe5b018190555050505050505050610fc7565b600260008260208110610ed757fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b60208310610f335780518252602082019150602081019050602083039250610f10565b6001836020036101000a038019825116818451168082178552505050505050905001915050602060405180830381855afa158015610f75573d6000803e3d6000fd5b5050506040513d6020811015610f8a57600080fd5b8101908080519060200190929190505050925060028281610fa757fe5b0491508080600101915050610e95565b506000610fc057fe5b5050505050505b50505050505050565b6060610fdd602054611314565b905090565b6000806000602054905060008090505b60208110156111d057600180831614156110e05760026000826020811061101557fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b60208310611071578051825260208201915060208101905060208303925061104e565b6001836020036101000a038019825116818451168082178552505050505050905001915050602060405180830381855afa1580156110b3573d6000803e3d6000fd5b5050506040513d60208110156110c857600080fd5b810190808051906020019092919050505092506111b6565b600283602183602081106110f057fe5b015460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061114b5780518252602082019150602081019050602083039250611128565b6001836020036101000a038019825116818451168082178552505050505050905001915050602060405180830381855afa15801561118d573d6000803e3d6000fd5b5050506040513d60208110156111a257600080fd5b810190808051906020019092919050505092505b600282816111c057fe5b0491508080600101915050610ff2565b506002826111df602054611314565b600060401b6040516020018084815260200183805190602001908083835b6020831061122057805182526020820191506020810190506020830392506111fd565b6001836020036101000a0380198251168184511680821785525050505050509050018267ffffffffffffffff191667ffffffffffffffff1916815260180193505050506040516020818303038152906040526040518082805190602001908083835b602083106112a55780518252602082019150602081019050602083039250611282565b6001836020036101000a038019825116818451168082178552505050505050905001915050602060405180830381855afa1580156112e7573d6000803e3d6000fd5b5050506040513d60208110156112fc57600080fd5b81019080805190602001909291905050509250505090565b6060600867ffffffffffffffff8111801561132e57600080fd5b506040519080825280601f01601f1916602001820160405280156113615781602001600182028036833780820191505090505b50905060008260c01b90508060076008811061137957fe5b1a60f81b8260008151811061138a57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350806006600881106113c657fe5b1a60f81b826001815181106113d757fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060056008811061141357fe5b1a60f81b8260028151811061142457fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060046008811061146057fe5b1a60f81b8260038151811061147157fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350806003600881106114ad57fe5b1a60f81b826004815181106114be57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350806002600881106114fa57fe5b1a60f81b8260058151811061150b57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060016008811061154757fe5b1a60f81b8260068151811061155857fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060006008811061159457fe5b1a60f81b826007815181106115a557fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535050919050565b600080858511156115ea57600080fd5b838611156115f757600080fd5b600185028301915084860390509450949250505056fe4465706f736974436f6e74726163743a206d65726b6c6520747265652066756c6c4465706f736974436f6e74726163743a207265636f6e7374727563746564204465706f7369744461746120646f6573206e6f74206d6174636820737570706c696564206465706f7369745f646174615f726f6f744465706f736974436f6e74726163743a20696e76616c6964207769746864726177616c5f63726564656e7469616c73206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c7565206e6f74206d756c7469706c65206f6620677765694465706f736974436f6e74726163743a20696e76616c6964207075626b6579206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f20686967684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f206c6f774465706f736974436f6e74726163743a20696e76616c6964207369676e6174757265206c656e677468a2646970667358221220230afd4b6e3551329e50f1239e08fa3ab7907b77403c4f237d9adf679e8e43cf64736f6c634300060b0033" + "123463a4b065722e99115d6c222f267d9cabb524": { + "balance": "0x43c33c1937564800000" + }, + "4242424242424242424242424242424242424242": { + "code": "0x60806040526004361061003f5760003560e01c806301ffc9a71461004457806322895118146100b6578063621fd130146101e3578063c5f2892f14610273575b600080fd5b34801561005057600080fd5b5061009c6004803603602081101561006757600080fd5b8101908080357bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916906020019092919050505061029e565b604051808215151515815260200191505060405180910390f35b6101e1600480360360808110156100cc57600080fd5b81019080803590602001906401000000008111156100e957600080fd5b8201836020820111156100fb57600080fd5b8035906020019184600183028401116401000000008311171561011d57600080fd5b90919293919293908035906020019064010000000081111561013e57600080fd5b82018360208201111561015057600080fd5b8035906020019184600183028401116401000000008311171561017257600080fd5b90919293919293908035906020019064010000000081111561019357600080fd5b8201836020820111156101a557600080fd5b803590602001918460018302840111640100000000831117156101c757600080fd5b909192939192939080359060200190929190505050610370565b005b3480156101ef57600080fd5b506101f8610fd0565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561023857808201518184015260208101905061021d565b50505050905090810190601f1680156102655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561027f57600080fd5b50610288610fe2565b6040518082815260200191505060405180910390f35b60007f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916148061036957507f85640907000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b9050919050565b603087879050146103cc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806116ec6026913960400191505060405180910390fd5b60208585905014610428576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260368152602001806116836036913960400191505060405180910390fd5b60608383905014610484576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602981526020018061175f6029913960400191505060405180910390fd5b670de0b6b3a76400003410156104e5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806117396026913960400191505060405180910390fd5b6000633b9aca0034816104f457fe5b061461054b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260338152602001806116b96033913960400191505060405180910390fd5b6000633b9aca00348161055a57fe5b04905067ffffffffffffffff80168111156105c0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260278152602001806117126027913960400191505060405180910390fd5b60606105cb82611314565b90507f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c589898989858a8a610600602054611314565b60405180806020018060200180602001806020018060200186810386528e8e82818152602001925080828437600081840152601f19601f82011690508083019250505086810385528c8c82818152602001925080828437600081840152601f19601f82011690508083019250505086810384528a818151815260200191508051906020019080838360005b838110156106a657808201518184015260208101905061068b565b50505050905090810190601f1680156106d35780820380516001836020036101000a031916815260200191505b508681038352898982818152602001925080828437600081840152601f19601f820116905080830192505050868103825287818151815260200191508051906020019080838360005b8381101561073757808201518184015260208101905061071c565b50505050905090810190601f1680156107645780820380516001836020036101000a031916815260200191505b509d505050505050505050505050505060405180910390a1600060028a8a600060801b6040516020018084848082843780830192505050826fffffffffffffffffffffffffffffffff19166fffffffffffffffffffffffffffffffff1916815260100193505050506040516020818303038152906040526040518082805190602001908083835b6020831061080e57805182526020820191506020810190506020830392506107eb565b6001836020036101000a038019825116818451168082178552505050505050905001915050602060405180830381855afa158015610850573d6000803e3d6000fd5b5050506040513d602081101561086557600080fd5b8101908080519060200190929190505050905060006002808888600090604092610891939291906115da565b6040516020018083838082843780830192505050925050506040516020818303038152906040526040518082805190602001908083835b602083106108eb57805182526020820191506020810190506020830392506108c8565b6001836020036101000a038019825116818451168082178552505050505050905001915050602060405180830381855afa15801561092d573d6000803e3d6000fd5b5050506040513d602081101561094257600080fd5b8101908080519060200190929190505050600289896040908092610968939291906115da565b6000801b604051602001808484808284378083019250505082815260200193505050506040516020818303038152906040526040518082805190602001908083835b602083106109cd57805182526020820191506020810190506020830392506109aa565b6001836020036101000a038019825116818451168082178552505050505050905001915050602060405180830381855afa158015610a0f573d6000803e3d6000fd5b5050506040513d6020811015610a2457600080fd5b810190808051906020019092919050505060405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b60208310610a8e5780518252602082019150602081019050602083039250610a6b565b6001836020036101000a038019825116818451168082178552505050505050905001915050602060405180830381855afa158015610ad0573d6000803e3d6000fd5b5050506040513d6020811015610ae557600080fd5b810190808051906020019092919050505090506000600280848c8c604051602001808481526020018383808284378083019250505093505050506040516020818303038152906040526040518082805190602001908083835b60208310610b615780518252602082019150602081019050602083039250610b3e565b6001836020036101000a038019825116818451168082178552505050505050905001915050602060405180830381855afa158015610ba3573d6000803e3d6000fd5b5050506040513d6020811015610bb857600080fd5b8101908080519060200190929190505050600286600060401b866040516020018084805190602001908083835b60208310610c085780518252602082019150602081019050602083039250610be5565b6001836020036101000a0380198251168184511680821785525050505050509050018367ffffffffffffffff191667ffffffffffffffff1916815260180182815260200193505050506040516020818303038152906040526040518082805190602001908083835b60208310610c935780518252602082019150602081019050602083039250610c70565b6001836020036101000a038019825116818451168082178552505050505050905001915050602060405180830381855afa158015610cd5573d6000803e3d6000fd5b5050506040513d6020811015610cea57600080fd5b810190808051906020019092919050505060405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b60208310610d545780518252602082019150602081019050602083039250610d31565b6001836020036101000a038019825116818451168082178552505050505050905001915050602060405180830381855afa158015610d96573d6000803e3d6000fd5b5050506040513d6020811015610dab57600080fd5b81019080805190602001909291905050509050858114610e16576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252605481526020018061162f6054913960600191505060405180910390fd5b6001602060020a0360205410610e77576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602181526020018061160e6021913960400191505060405180910390fd5b60016020600082825401925050819055506000602054905060008090505b6020811015610fb75760018083161415610ec8578260008260208110610eb757fe5b018190555050505050505050610fc7565b600260008260208110610ed757fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b60208310610f335780518252602082019150602081019050602083039250610f10565b6001836020036101000a038019825116818451168082178552505050505050905001915050602060405180830381855afa158015610f75573d6000803e3d6000fd5b5050506040513d6020811015610f8a57600080fd5b8101908080519060200190929190505050925060028281610fa757fe5b0491508080600101915050610e95565b506000610fc057fe5b5050505050505b50505050505050565b6060610fdd602054611314565b905090565b6000806000602054905060008090505b60208110156111d057600180831614156110e05760026000826020811061101557fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b60208310611071578051825260208201915060208101905060208303925061104e565b6001836020036101000a038019825116818451168082178552505050505050905001915050602060405180830381855afa1580156110b3573d6000803e3d6000fd5b5050506040513d60208110156110c857600080fd5b810190808051906020019092919050505092506111b6565b600283602183602081106110f057fe5b015460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061114b5780518252602082019150602081019050602083039250611128565b6001836020036101000a038019825116818451168082178552505050505050905001915050602060405180830381855afa15801561118d573d6000803e3d6000fd5b5050506040513d60208110156111a257600080fd5b810190808051906020019092919050505092505b600282816111c057fe5b0491508080600101915050610ff2565b506002826111df602054611314565b600060401b6040516020018084815260200183805190602001908083835b6020831061122057805182526020820191506020810190506020830392506111fd565b6001836020036101000a0380198251168184511680821785525050505050509050018267ffffffffffffffff191667ffffffffffffffff1916815260180193505050506040516020818303038152906040526040518082805190602001908083835b602083106112a55780518252602082019150602081019050602083039250611282565b6001836020036101000a038019825116818451168082178552505050505050905001915050602060405180830381855afa1580156112e7573d6000803e3d6000fd5b5050506040513d60208110156112fc57600080fd5b81019080805190602001909291905050509250505090565b6060600867ffffffffffffffff8111801561132e57600080fd5b506040519080825280601f01601f1916602001820160405280156113615781602001600182028036833780820191505090505b50905060008260c01b90508060076008811061137957fe5b1a60f81b8260008151811061138a57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350806006600881106113c657fe5b1a60f81b826001815181106113d757fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060056008811061141357fe5b1a60f81b8260028151811061142457fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060046008811061146057fe5b1a60f81b8260038151811061147157fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350806003600881106114ad57fe5b1a60f81b826004815181106114be57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350806002600881106114fa57fe5b1a60f81b8260058151811061150b57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060016008811061154757fe5b1a60f81b8260068151811061155857fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060006008811061159457fe5b1a60f81b826007815181106115a557fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535050919050565b600080858511156115ea57600080fd5b838611156115f757600080fd5b600185028301915084860390509450949250505056fe4465706f736974436f6e74726163743a206d65726b6c6520747265652066756c6c4465706f736974436f6e74726163743a207265636f6e7374727563746564204465706f7369744461746120646f6573206e6f74206d6174636820737570706c696564206465706f7369745f646174615f726f6f744465706f736974436f6e74726163743a20696e76616c6964207769746864726177616c5f63726564656e7469616c73206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c7565206e6f74206d756c7469706c65206f6620677765694465706f736974436f6e74726163743a20696e76616c6964207075626b6579206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f20686967684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f206c6f774465706f736974436f6e74726163743a20696e76616c6964207369676e6174757265206c656e677468a2646970667358221220230afd4b6e3551329e50f1239e08fa3ab7907b77403c4f237d9adf679e8e43cf64736f6c634300060b0033", + "storage": { + "0x0000000000000000000000000000000000000000000000000000000000000022": "0xf5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb4b", + "0x0000000000000000000000000000000000000000000000000000000000000023": "0xdb56114e00fdd4c1f85c892bf35ac9a89289aaecb1ebd0a96cde606a748b5d71", + "0x0000000000000000000000000000000000000000000000000000000000000024": "0xc78009fdf07fc56a11f122370658a353aaa542ed63e44c4bc15ff4cd105ab33c", + "0x0000000000000000000000000000000000000000000000000000000000000025": "0x536d98837f2dd165a55d5eeae91485954472d56f246df256bf3cae19352a123c", + "0x0000000000000000000000000000000000000000000000000000000000000026": "0x9efde052aa15429fae05bad4d0b1d7c64da64d03d7a1854a588c2cb8430c0d30", + "0x0000000000000000000000000000000000000000000000000000000000000027": "0xd88ddfeed400a8755596b21942c1497e114c302e6118290f91e6772976041fa1", + "0x0000000000000000000000000000000000000000000000000000000000000028": "0x87eb0ddba57e35f6d286673802a4af5975e22506c7cf4c64bb6be5ee11527f2c", + "0x0000000000000000000000000000000000000000000000000000000000000029": "0x26846476fd5fc54a5d43385167c95144f2643f533cc85bb9d16b782f8d7db193", + "0x000000000000000000000000000000000000000000000000000000000000002a": "0x506d86582d252405b840018792cad2bf1259f1ef5aa5f887e13cb2f0094f51e1", + "0x000000000000000000000000000000000000000000000000000000000000002b": "0xffff0ad7e659772f9534c195c815efc4014ef1e1daed4404c06385d11192e92b", + "0x000000000000000000000000000000000000000000000000000000000000002c": "0x6cf04127db05441cd833107a52be852868890e4317e6a02ab47683aa75964220", + "0x000000000000000000000000000000000000000000000000000000000000002d": "0xb7d05f875f140027ef5118a2247bbb84ce8f2f0f1123623085daf7960c329f5f", + "0x000000000000000000000000000000000000000000000000000000000000002e": "0xdf6af5f5bbdb6be9ef8aa618e4bf8073960867171e29676f8b284dea6a08a85e", + "0x000000000000000000000000000000000000000000000000000000000000002f": "0xb58d900f5e182e3c50ef74969ea16c7726c549757cc23523c369587da7293784", + "0x0000000000000000000000000000000000000000000000000000000000000030": "0xd49a7502ffcfb0340b1d7885688500ca308161a7f96b62df9d083b71fcc8f2bb", + "0x0000000000000000000000000000000000000000000000000000000000000031": "0x8fe6b1689256c0d385f42f5bbe2027a22c1996e110ba97c171d3e5948de92beb", + "0x0000000000000000000000000000000000000000000000000000000000000032": "0x8d0d63c39ebade8509e0ae3c9c3876fb5fa112be18f905ecacfecb92057603ab", + "0x0000000000000000000000000000000000000000000000000000000000000033": "0x95eec8b2e541cad4e91de38385f2e046619f54496c2382cb6cacd5b98c26f5a4", + "0x0000000000000000000000000000000000000000000000000000000000000034": "0xf893e908917775b62bff23294dbbe3a1cd8e6cc1c35b4801887b646a6f81f17f", + "0x0000000000000000000000000000000000000000000000000000000000000035": "0xcddba7b592e3133393c16194fac7431abf2f5485ed711db282183c819e08ebaa", + "0x0000000000000000000000000000000000000000000000000000000000000036": "0x8a8d7fe3af8caa085a7639a832001457dfb9128a8061142ad0335629ff23ff9c", + "0x0000000000000000000000000000000000000000000000000000000000000037": "0xfeb3c337d7a51a6fbf00b9e34c52e1c9195c969bd4e7a0bfd51d5c5bed9c1167", + "0x0000000000000000000000000000000000000000000000000000000000000038": "0xe71f0aa83cc32edfbefa9f4d3e0174ca85182eec9f3a09f6a6c0df6377a510d7", + "0x0000000000000000000000000000000000000000000000000000000000000039": "0x31206fa80a50bb6abe29085058f16212212a60eec8f049fecb92d8c8e0a84bc0", + "0x000000000000000000000000000000000000000000000000000000000000003a": "0x21352bfecbeddde993839f614c3dac0a3ee37543f9b412b16199dc158e23b544", + "0x000000000000000000000000000000000000000000000000000000000000003b": "0x619e312724bb6d7c3153ed9de791d764a366b389af13c58bf8a8d90481a46765", + "0x000000000000000000000000000000000000000000000000000000000000003c": "0x7cdd2986268250628d0c10e385c58c6191e6fbe05191bcc04f133f2cea72c1c4", + "0x000000000000000000000000000000000000000000000000000000000000003d": "0x848930bd7ba8cac54661072113fb278869e07bb8587f91392933374d017bcbe1", + "0x000000000000000000000000000000000000000000000000000000000000003e": "0x8869ff2c22b28cc10510d9853292803328be4fb0e80495e8bb8d271f5b889636", + "0x000000000000000000000000000000000000000000000000000000000000003f": "0xb5fe28e79f1b850f8658246ce9b6a1e7b49fc06db7143e8fe0b4f2b0c5523a5c", + "0x0000000000000000000000000000000000000000000000000000000000000040": "0x985e929f70af28d0bdd1a90a808f977f597c7c778c489e98d3bd8910d31ac0f7" + }, + "balance": "0x0" } - } -}` - -// generateGenesis returns a genesis with specified params -func generateGenesis(blockTimeSecs int, chainID int, signerAddrs, prefundedAddrs []string) (string, error) { - var genesisJSON map[string]interface{} - - err := json.Unmarshal([]byte(_baseGenesis), &genesisJSON) - if err != nil { - return "", err - } - - // add the prefunded prefundedAddrs - for _, account := range prefundedAddrs { - genesisJSON["alloc"].(map[string]interface{})[account] = map[string]string{"balance": "7500000000000000000000000000000"} - } - - // set the block prod speed - genesisJSON["config"].(map[string]interface{})["clique"].(map[string]interface{})["period"] = blockTimeSecs - - // set the network id - genesisJSON["config"].(map[string]interface{})["chainId"] = chainID - - // set the signers addrs + remove the 0x - for i := range signerAddrs { - signerAddrs[i] = signerAddrs[i][2:] - } - genesisJSON["extradata"] = fmt.Sprintf("0x0000000000000000000000000000000000000000000000000000000000000000%s0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", strings.Join(signerAddrs, "")) - - genesisBytes, err := json.MarshalIndent(genesisJSON, "", " ") - if err != nil { - return "", err - } - - return string(genesisBytes), nil -} + }, + "number": "0x0", + "gasUsed": "0x0", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "baseFeePerGas": null, + "excessBlobGas": null, + "blobGasUsed": null +} \ No newline at end of file diff --git a/integration/eth2network/jwt.hex b/integration/eth2network/jwt.hex new file mode 100644 index 0000000000..c4454fe4fa --- /dev/null +++ b/integration/eth2network/jwt.hex @@ -0,0 +1 @@ +0xfad2709d0bb03bf0e8ba3c99bea194575d3e98863133d1af638ed056d1d59345 \ No newline at end of file diff --git a/integration/eth2network/main/cli.go b/integration/eth2network/main/cli.go index 26abbdc591..1f854d8736 100644 --- a/integration/eth2network/main/cli.go +++ b/integration/eth2network/main/cli.go @@ -9,8 +9,8 @@ import ( const ( // Flag names and usages. - numNodesName = "numNodes" - numNodesUsage = "The number of nodes on the network" + chainIDName = "chainId" + chainIDUsage = "The chain Id to use by the eth2 network" gethHTTPStartPortName = "gethHTTPStartPort" gethHTTPStartPortUsage = "The initial port to start allocating ports from" @@ -27,65 +27,38 @@ const ( prysmBeaconRPCStartPortName = "prysmBeaconRPCStartPort" prysmBeaconRPCStartPortUsage = "The initial port to start allocating prysm rpc port" + prysmBeaconP2PStartPortName = "prysmBeaconP2PtartPort" + prysmBeaconP2PStartPortUsage = "The p2p udp prysm port" + prefundedAddrsName = "prefundedAddrs" prefundedAddrsUsage = "The addresses to prefund as a comma-separated list" - blockTimeSecsName = "blockTimeSecs" - blockTimeSecsUsage = "The block time in seconds" - - slotsPerEpochName = "slotsPerEpoch" - slotsPerEpochUsage = "The slot each POS epoch contains." - - secondsPerSlotName = "slotsPerSecond" - secondsPerSlotUsage = "The seconds each slot lasts." - - chainIDName = "chainId" - chainIDUsage = "The chain Id to use by the eth2 network" - - onlyDownloadName = "onlyDownload" - onlyDownloadUsage = "Only downloads the necessary files doesn't start the network" - logLevelName = "logLevel" logLevelUsage = "logLevel" - - logToFileName = "logToFile" - logToFileUsage = "Whether files are logged to files or stdout" ) type ethConfig struct { - numNodes int + chainID int gethHTTPStartPort int gethWSStartPort int gethAuthRPCStartPort int gethNetworkStartPort int prysmBeaconRPCStartPort int prysmBeaconP2PStartPort int - blockTimeSecs int - slotsPerEpoch int - secondsPerSlot int logLevel int - chainID int - onlyDownload bool - logToFile bool prefundedAddrs []string } func defaultConfig() *ethConfig { return ðConfig{ chainID: 1337, - numNodes: 1, gethHTTPStartPort: 12000, gethWSStartPort: 12100, gethAuthRPCStartPort: 12200, gethNetworkStartPort: 12300, prysmBeaconRPCStartPort: 12400, prysmBeaconP2PStartPort: 12500, - onlyDownload: false, prefundedAddrs: []string{}, - blockTimeSecs: 1, - slotsPerEpoch: 2, - secondsPerSlot: 2, - logToFile: true, logLevel: int(gethlog.LvlDebug), } } @@ -93,22 +66,15 @@ func defaultConfig() *ethConfig { func parseCLIArgs() *ethConfig { defaultConfig := defaultConfig() - onlyDownload := flag.Bool(onlyDownloadName, defaultConfig.onlyDownload, onlyDownloadUsage) - numNodes := flag.Int(numNodesName, defaultConfig.numNodes, numNodesUsage) - startPort := flag.Int(gethHTTPStartPortName, defaultConfig.gethHTTPStartPort, gethHTTPStartPortUsage) - websocketStartPort := flag.Int(websocketStartPortName, defaultConfig.gethWSStartPort, websocketStartPortUsage) - prefundedAddrs := flag.String(prefundedAddrsName, "", prefundedAddrsUsage) - blockTimeSecs := flag.Int(blockTimeSecsName, defaultConfig.blockTimeSecs, blockTimeSecsUsage) - secondsPerSlot := flag.Int(secondsPerSlotName, defaultConfig.secondsPerSlot, secondsPerSlotUsage) - slotsPerEpoch := flag.Int(slotsPerEpochName, defaultConfig.slotsPerEpoch, slotsPerEpochUsage) - - logLevel := flag.Int(logLevelName, defaultConfig.logLevel, logLevelUsage) - logToFile := flag.Bool(logToFileName, defaultConfig.logToFile, logToFileUsage) chainID := flag.Int(chainIDName, defaultConfig.chainID, chainIDUsage) - + gethHTTPPort := flag.Int(gethHTTPStartPortName, defaultConfig.gethHTTPStartPort, gethHTTPStartPortUsage) + gethWSPort := flag.Int(websocketStartPortName, defaultConfig.gethWSStartPort, websocketStartPortUsage) gethAuthRPCStartPort := flag.Int(gethAuthRPCStartPortName, defaultConfig.gethAuthRPCStartPort, gethAuthRPCStartPortUsage) gethNetworkStartPort := flag.Int(gethNetworkStartPortName, defaultConfig.gethNetworkStartPort, gethNetworkStartPortUsage) + prysmBeaconP2PStartPort := flag.Int(prysmBeaconP2PStartPortName, defaultConfig.prysmBeaconP2PStartPort, prysmBeaconP2PStartPortUsage) prysmBeaconRPCStartPort := flag.Int(prysmBeaconRPCStartPortName, defaultConfig.prysmBeaconRPCStartPort, prysmBeaconRPCStartPortUsage) + logLevel := flag.Int(logLevelName, defaultConfig.logLevel, logLevelUsage) + prefundedAddrs := flag.String(prefundedAddrsName, "", prefundedAddrsUsage) flag.Parse() @@ -125,19 +91,14 @@ func parseCLIArgs() *ethConfig { } return ðConfig{ - numNodes: *numNodes, chainID: *chainID, - gethHTTPStartPort: *startPort, - gethWSStartPort: *websocketStartPort, - prefundedAddrs: parsedPrefundedAddrs, - blockTimeSecs: *blockTimeSecs, - slotsPerEpoch: *slotsPerEpoch, - secondsPerSlot: *secondsPerSlot, - logLevel: *logLevel, - logToFile: *logToFile, + gethHTTPStartPort: *gethHTTPPort, + gethWSStartPort: *gethWSPort, gethAuthRPCStartPort: *gethAuthRPCStartPort, gethNetworkStartPort: *gethNetworkStartPort, prysmBeaconRPCStartPort: *prysmBeaconRPCStartPort, - onlyDownload: *onlyDownload, + prysmBeaconP2PStartPort: *prysmBeaconP2PStartPort, + logLevel: *logLevel, + prefundedAddrs: parsedPrefundedAddrs, } } diff --git a/integration/eth2network/main/main.go b/integration/eth2network/main/main.go index 2a865e9630..bc00d23230 100644 --- a/integration/eth2network/main/main.go +++ b/integration/eth2network/main/main.go @@ -16,31 +16,22 @@ func main() { fmt.Printf("Starting eth2network with params: %+v\n", config) - binariesPath, err := eth2network.EnsureBinariesExist() + binDir, err := eth2network.EnsureBinariesExist() if err != nil { panic(err) } - if config.onlyDownload { - os.Exit(0) - } - - eth2Network := eth2network.NewEth2Network( - binariesPath, - config.logToFile, - config.gethHTTPStartPort, - config.gethWSStartPort, - config.gethAuthRPCStartPort, + eth2Network := eth2network.NewPosEth2Network( + binDir, config.gethNetworkStartPort, - config.prysmBeaconRPCStartPort, + config.prysmBeaconP2PStartPort, + config.gethAuthRPCStartPort, + config.gethWSStartPort, + config.gethHTTPStartPort, config.prysmBeaconRPCStartPort, config.chainID, - config.numNodes, - config.blockTimeSecs, - config.slotsPerEpoch, - config.secondsPerSlot, - config.prefundedAddrs, - 5*time.Minute, + 6*time.Minute, + config.prefundedAddrs..., ) err = eth2Network.Start() @@ -54,7 +45,7 @@ func main() { } // Shuts down the Geth network when an interrupt is received. -func handleInterrupt(network eth2network.Eth2Network) { +func handleInterrupt(network eth2network.PosEth2Network) { interruptChannel := make(chan os.Signal, 1) signal.Notify(interruptChannel, os.Interrupt, syscall.SIGTERM) <-interruptChannel diff --git a/integration/eth2network/password.txt b/integration/eth2network/password.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/integration/eth2network/pk.txt b/integration/eth2network/pk.txt new file mode 100644 index 0000000000..69caa7ec4f --- /dev/null +++ b/integration/eth2network/pk.txt @@ -0,0 +1 @@ +2e0834786285daccd064ca17f1654f67b4aef298acbb82cef9ec422fb4975622 \ No newline at end of file diff --git a/integration/eth2network/pos_eth2_network.go b/integration/eth2network/pos_eth2_network.go new file mode 100644 index 0000000000..fb65cab6d3 --- /dev/null +++ b/integration/eth2network/pos_eth2_network.go @@ -0,0 +1,388 @@ +package eth2network + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "os" + "os/exec" + "path" + "path/filepath" + "runtime" + "strconv" + "strings" + "time" + + "golang.org/x/sync/errgroup" + + gethcommon "github.com/ethereum/go-ethereum/common" + "github.com/ten-protocol/go-ten/go/common/retry" + "github.com/ten-protocol/go-ten/integration" + + "github.com/ethereum/go-ethereum/ethclient" +) + +const ( + _eth2BinariesRelPath = "../.build/eth2_bin" + _gethBinaryName = "geth" +) + +var ( + gethFileNameVersion = fmt.Sprintf("geth-%s-%s-%s", runtime.GOOS, runtime.GOARCH, _gethVersion) + prysmBeaconChainFileNameVersion = fmt.Sprintf("beacon-chain-%s-%s-%s", _prysmVersion, runtime.GOOS, runtime.GOARCH) + prysmCTLFileNameVersion = fmt.Sprintf("prysmctl-%s-%s-%s", _prysmVersion, runtime.GOOS, runtime.GOARCH) + prysmValidatorFileNameVersion = fmt.Sprintf("validator-%s-%s-%s", _prysmVersion, runtime.GOOS, runtime.GOARCH) +) + +type PosImpl struct { + buildDir string + binDir string + chainID int + gethBinaryPath string + prysmBinaryPath string + prysmBeaconBinaryPath string + prysmValidatorBinaryPath string + gethNetworkPort int + beaconP2PPort int + gethWSPort int + gethRPCPort int + gethHTTPPort int + beaconRPCPort int + gethLogFile string + prysmBeaconLogFile string + prysmValidatorLogFile string + gethdataDir string + beacondataDir string + validatordataDir string + gethGenesisBytes []byte + gethProcessID int + beaconProcessID int + validatorProcessID int + wallets []string + timeout time.Duration +} + +type PosEth2Network interface { + Start() error + Stop() error + GenesisBytes() []byte +} + +func NewPosEth2Network(binDir string, gethNetworkPort, beaconP2PPort, gethRPCPort, gethWSPort, gethHTTPPort, beaconRPCPort, chainID int, timeout time.Duration, walletsToFund ...string) PosEth2Network { + build, err := getBuildNumber() + if err != nil { + panic(fmt.Sprintf("could not get build number: %s", err.Error())) + } + buildString := strconv.Itoa(build) + buildDir := path.Join(basepath, "../.build/eth2", buildString) + + gethBinaryPath := path.Join(binDir, gethFileNameVersion, _gethBinaryName) + prysmBeaconBinaryPath := path.Join(binDir, prysmBeaconChainFileNameVersion) + prysmBinaryPath := path.Join(binDir, prysmCTLFileNameVersion) + prysmValidatorBinaryPath := path.Join(binDir, prysmValidatorFileNameVersion) + + // we overwrite when we exceed the max path length for eth2 logs + if _, err := os.Stat(buildDir); err == nil { + fmt.Printf("Folder %s already exists, overwriting\n", buildDir) + err := os.RemoveAll(buildDir) + if err != nil { + panic(fmt.Sprintf("could not remove existing folder %s: %s", buildDir, err.Error())) + } + } + + err = os.MkdirAll(buildDir, os.ModePerm) + if err != nil { + panic(err) + } + + gethLogFile := path.Join(buildDir, "geth.log") + prysmBeaconLogFile := path.Join(buildDir, "beacon-chain.log") + prysmValidatorLogFile := path.Join(buildDir, "validator.log") + + gethdataDir := path.Join(buildDir, "/gethdata") + beacondataDir := path.Join(buildDir, "/beacondata") + validatordataDir := path.Join(buildDir, "/validatordata") + + if err = os.MkdirAll(gethdataDir, os.ModePerm); err != nil { + panic(err) + } + if err = os.MkdirAll(beacondataDir, os.ModePerm); err != nil { + panic(err) + } + if err = os.MkdirAll(validatordataDir, os.ModePerm); err != nil { + panic(err) + } + + genesis, err := fundWallets(walletsToFund, buildDir, chainID) + if err != nil { + panic(fmt.Sprintf("could not generate genesis. cause: %s", err.Error())) + } + + return &PosImpl{ + buildDir: buildDir, + binDir: binDir, + chainID: chainID, + gethNetworkPort: gethNetworkPort, + beaconP2PPort: beaconP2PPort, + gethWSPort: gethWSPort, + gethRPCPort: gethRPCPort, + gethHTTPPort: gethHTTPPort, + beaconRPCPort: beaconRPCPort, + gethBinaryPath: gethBinaryPath, + prysmBinaryPath: prysmBinaryPath, + prysmBeaconBinaryPath: prysmBeaconBinaryPath, + prysmValidatorBinaryPath: prysmValidatorBinaryPath, + gethLogFile: gethLogFile, + prysmBeaconLogFile: prysmBeaconLogFile, + prysmValidatorLogFile: prysmValidatorLogFile, + gethdataDir: gethdataDir, + beacondataDir: beacondataDir, + validatordataDir: validatordataDir, + gethGenesisBytes: []byte(genesis), + wallets: walletsToFund, + timeout: timeout, + } +} + +func (n *PosImpl) Start() error { + startTime := time.Now() + var eg errgroup.Group + if err := n.checkExistingNetworks(); err != nil { + return err + } + + err := eg.Wait() + go func() { + n.gethProcessID, n.beaconProcessID, n.validatorProcessID, err = startNetworkScript(n.gethNetworkPort, n.beaconP2PPort, + n.gethRPCPort, n.gethHTTPPort, n.gethWSPort, n.beaconRPCPort, n.chainID, n.buildDir, n.prysmBeaconLogFile, + n.prysmValidatorLogFile, n.gethLogFile, n.prysmBeaconBinaryPath, n.prysmBinaryPath, n.prysmValidatorBinaryPath, + n.gethBinaryPath, n.gethdataDir, n.beacondataDir, n.validatordataDir) + time.Sleep(time.Second) + }() + + if err != nil { + return fmt.Errorf("could not run the script to start l1 pos network. Cause: %s", err.Error()) + } + return n.waitForMergeEvent(startTime) +} + +func (n *PosImpl) Stop() error { + kill(n.gethProcessID) + kill(n.beaconProcessID) + kill(n.validatorProcessID) + time.Sleep(time.Second) + return nil +} + +func (n *PosImpl) checkExistingNetworks() error { + port := n.gethWSPort + _, err := ethclient.Dial(fmt.Sprintf("ws://127.0.0.1:%d", port)) + if err == nil { + return fmt.Errorf("unexpected geth node is active before the network is started") + } + return nil +} + +// waitForMergeEvent connects to the geth node and waits until block 2 (the merge block) is reached +func (n *PosImpl) waitForMergeEvent(startTime time.Time) error { + ctx := context.Background() + dial, err := ethclient.Dial(fmt.Sprintf("http://127.0.0.1:%d", n.gethHTTPPort)) + if err != nil { + return err + } + time.Sleep(2 * time.Second) + number := uint64(0) + // wait for the merge block + err = retry.Do( + func() error { + number, err = dial.BlockNumber(ctx) + if err != nil { + return err + } + if number <= 7 { + return fmt.Errorf("has not arrived at The Merge") + } + return nil + }, + retry.NewTimeoutStrategy(n.timeout, time.Second), + ) + if err != nil { + return err + } + + fmt.Printf("Reached the merge block after %s\n", time.Since(startTime)) + + if err = n.prefundedBalanceActive(dial); err != nil { + fmt.Printf("Error prefunding account %s\n", err.Error()) + return err + } + return nil +} + +func (n *PosImpl) prefundedBalanceActive(client *ethclient.Client) error { + for _, addr := range n.wallets { + balance, err := client.BalanceAt(context.Background(), gethcommon.HexToAddress(addr), nil) + if err != nil { + return fmt.Errorf("unable to check balance for account %s - %w", addr, err) + } + if balance.Cmp(gethcommon.Big0) == 0 { + return fmt.Errorf("unexpected %s balance for account %s", balance.String(), addr) + } + fmt.Printf("Account %s prefunded with %s\n", addr, balance.String()) + } + return nil +} + +func (n *PosImpl) GenesisBytes() []byte { + return n.gethGenesisBytes +} + +func startNetworkScript(gethNetworkPort, beaconP2PPort, gethRPCPort, gethHTTPPort, gethWSPort, beaconRPCPort, chainID int, buildDir, beaconLogFile, validatorLogFile, gethLogFile, + beaconBinary, prysmBinary, validatorBinary, gethBinary, gethdataDir, beacondataDir, validatordataDir string, +) (int, int, int, error) { + startScript := filepath.Join(basepath, "start-pos-network.sh") + gethNetworkPortStr := strconv.Itoa(gethNetworkPort) + beaconP2PPortStr := strconv.Itoa(beaconP2PPort) + beaconRPCPortStr := strconv.Itoa(beaconRPCPort) + gethHTTPPortStr := strconv.Itoa(gethHTTPPort) + gethWSPortStr := strconv.Itoa(gethWSPort) + gethRPCPortStr := strconv.Itoa(gethRPCPort) + chainStr := strconv.Itoa(chainID) + + cmd := exec.Command("/bin/bash", startScript, + "--geth-network", gethNetworkPortStr, + "--beacon-p2p", beaconP2PPortStr, + "--geth-http", gethHTTPPortStr, + "--geth-ws", gethWSPortStr, + "--geth-rpc", gethRPCPortStr, + "--beacon-rpc", beaconRPCPortStr, + "--chainid", chainStr, + "--build-dir", buildDir, + "--base-path", basepath, + "--beacon-log", beaconLogFile, + "--validator-log", validatorLogFile, + "--geth-log", gethLogFile, + "--beacon-binary", beaconBinary, + "--prysmctl-binary", prysmBinary, + "--validator-binary", validatorBinary, + "--geth-binary", gethBinary, + "--gethdata-dir", gethdataDir, + "--beacondata-dir", beacondataDir, + "--validatordata-dir", validatordataDir, + ) + var out bytes.Buffer + cmd.Stdout = &out + cmd.Stderr = &out + + err := cmd.Run() + if err != nil { + panic(fmt.Errorf("failed to start network script: %w\nOutput: %s", err, out.String())) + } + + output := out.String() + return _parsePIDs(output) +} + +// we have to run all the processes from the same script for the geth.ipc to work for some reason so this is an ugly +// workaround to capture the PIDs, so we can kill each process individually +func _parsePIDs(output string) (int, int, int, error) { + lines := strings.Split(output, "\n") + var gethPID, beaconPID, validatorPID int + var err error + + // reverse order since PIDS are in the last three lines + for i := len(lines) - 1; i >= 0; i-- { + line := lines[i] + if strings.Contains(line, "GETH PID") { + fields := strings.Fields(line) + pidStr := fields[len(fields)-1] + gethPID, err = strconv.Atoi(pidStr) + if err != nil { + return 0, 0, 0, fmt.Errorf("failed to parse GETH PID: %w", err) + } + } else if strings.Contains(line, "BEACON PID") { + fields := strings.Fields(line) + pidStr := fields[len(fields)-1] + beaconPID, err = strconv.Atoi(pidStr) + if err != nil { + return 0, 0, 0, fmt.Errorf("failed to parse BEACON PID: %w", err) + } + } else if strings.Contains(line, "VALIDATOR PID") { + fields := strings.Fields(line) + pidStr := fields[len(fields)-1] + validatorPID, err = strconv.Atoi(pidStr) + if err != nil { + return 0, 0, 0, fmt.Errorf("failed to parse VALIDATOR PID: %w", err) + } + } + + // finish loop early when PIDs are found + if gethPID != 0 && beaconPID != 0 && validatorPID != 0 { + break + } + } + + if gethPID == 0 || beaconPID == 0 || validatorPID == 0 { + return 0, 0, 0, fmt.Errorf("failed to find all required PIDs in script output") + } + + return gethPID, beaconPID, validatorPID, nil +} + +// we parse the wallet addresses and append them to the genesis json, using an intermediate file which is cleaned up +// at the end of the network script. genesis bytes are returned to be parsed to the enclave config +func fundWallets(walletsToFund []string, buildDir string, chainID int) (string, error) { + filePath := filepath.Join(basepath, "genesis-init.json") + genesis, err := os.ReadFile(filePath) + if err != nil { + return "", err + } + + var genesisJSON map[string]interface{} + err = json.Unmarshal(genesis, &genesisJSON) + if err != nil { + return "", err + } + + walletsToFund = append(walletsToFund, integration.GethNodeAddress) + for _, account := range walletsToFund { + genesisJSON["alloc"].(map[string]interface{})[account] = map[string]string{"balance": "7500000000000000000000000000000"} + } + + // set the chain ID + genesisJSON["config"].(map[string]interface{})["chainId"] = chainID + + formattedGenesisBytes, err := json.MarshalIndent(genesisJSON, "", " ") + if err != nil { + return "", err + } + + newFile := filepath.Join(buildDir, "genesis.json") + err = os.WriteFile(newFile, formattedGenesisBytes, 0o644) //nolint:gosec + if err != nil { + return "", err + } + + return string(formattedGenesisBytes), nil +} + +func kill(pid int) { + process, err := os.FindProcess(pid) + if err != nil { + fmt.Printf("Error finding process with PID %d: %v\n", pid, err) + return + } + + killErr := process.Kill() + if killErr != nil { + fmt.Printf("Error killing process with PID %d: %v\n", pid, killErr) + return + } + + time.Sleep(200 * time.Millisecond) + err = process.Release() + if err != nil { + fmt.Printf("Error releasing process with PID %d: %v\n", pid, err) + } +} diff --git a/integration/eth2network/pos_eth2_network_test.go b/integration/eth2network/pos_eth2_network_test.go new file mode 100644 index 0000000000..7fb90bf3bb --- /dev/null +++ b/integration/eth2network/pos_eth2_network_test.go @@ -0,0 +1,160 @@ +package eth2network + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "io" + "math/big" + "net/http" + "strings" + "testing" + "time" + + "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/ethclient" + "github.com/stretchr/testify/assert" + "github.com/ten-protocol/go-ten/go/common" + "github.com/ten-protocol/go-ten/go/ethadapter" + "github.com/ten-protocol/go-ten/go/wallet" + "github.com/ten-protocol/go-ten/integration" + "github.com/ten-protocol/go-ten/integration/datagenerator" + + gethcommon "github.com/ethereum/go-ethereum/common" + gethlog "github.com/ethereum/go-ethereum/log" +) + +const ( + _startPort = integration.StartPortEth2NetworkTests +) + +func TestEnsureBinariesAreAvail(t *testing.T) { + path, err := EnsureBinariesExist() + assert.Nil(t, err) + t.Logf("Successfully downloaded files to %s", path) +} + +func TestStartPosEth2Network(t *testing.T) { + binDir, err := EnsureBinariesExist() + assert.Nil(t, err) + + network := NewPosEth2Network( + binDir, + _startPort+integration.DefaultGethNetworkPortOffset, + _startPort+integration.DefaultPrysmP2PPortOffset, + _startPort+integration.DefaultGethAUTHPortOffset, + _startPort+integration.DefaultGethWSPortOffset, + _startPort+integration.DefaultGethHTTPPortOffset, + _startPort+integration.DefaultPrysmRPCPortOffset, + integration.EthereumChainID, + 6*time.Minute, + ) + + // wait until the merge has happened + assert.Nil(t, network.Start()) + + defer network.Stop() //nolint: errcheck + + // test input configurations + t.Run("areConfigsUphold", func(t *testing.T) { + areConfigsUphold(t, gethcommon.HexToAddress(integration.GethNodeAddress), integration.EthereumChainID) + }) + + // test number of nodes + t.Run("numberOfNodes", func(t *testing.T) { + numberOfNodes(t) + }) + + minerWallet := wallet.NewInMemoryWalletFromConfig( + integration.GethNodePK, + integration.EthereumChainID, + gethlog.New()) + + t.Run("txsAreMinted", func(t *testing.T) { + txsAreMinted(t, minerWallet) + }) +} + +func areConfigsUphold(t *testing.T, addr gethcommon.Address, chainID int) { + url := fmt.Sprintf("http://127.0.0.1:%d", _startPort+integration.DefaultGethHTTPPortOffset) + conn, err := ethclient.Dial(url) + assert.Nil(t, err) + + at, err := conn.BalanceAt(context.Background(), addr, nil) + assert.Nil(t, err) + assert.True(t, at.Cmp(big.NewInt(1)) == 1) + + id, err := conn.NetworkID(context.Background()) + assert.Nil(t, err) + assert.Equal(t, int64(chainID), id.Int64()) +} + +func numberOfNodes(t *testing.T) { + url := fmt.Sprintf("http://127.0.0.1:%d", _startPort+integration.DefaultGethHTTPPortOffset) + + req, err := http.NewRequestWithContext( + context.Background(), + http.MethodPost, + url, + strings.NewReader(`{"jsonrpc": "2.0", "method": "net_peerCount", "params": [], "id": 1}`), + ) + assert.Nil(t, err) + req.Header.Set("Content-Type", "application/json; charset=UTF-8") + + client := &http.Client{} + response, err := client.Do(req) + assert.Nil(t, err) + + defer response.Body.Close() + body, err := io.ReadAll(response.Body) + assert.Nil(t, err) + + var res map[string]interface{} + err = json.Unmarshal(body, &res) + assert.Nil(t, err) + + err = json.Unmarshal(body, &res) + assert.Nil(t, err) + + assert.Equal(t, fmt.Sprintf("0x%x", 0), res["result"]) +} + +func txsAreMinted(t *testing.T, w wallet.Wallet) { + var err error + + ethClient, err := ethadapter.NewEthClient("127.0.0.1", uint(_startPort+integration.DefaultGethWSPortOffset), 30*time.Second, common.L2Address{}, gethlog.New()) + assert.Nil(t, err) + + toAddr := datagenerator.RandomAddress() + estimatedTx, err := ethClient.PrepareTransactionToSend(context.Background(), &types.LegacyTx{ + To: &toAddr, + Value: big.NewInt(100), + }, w.Address()) + assert.Nil(t, err) + + signedTx, err := w.SignTransaction(estimatedTx) + assert.Nil(t, err) + + err = ethClient.SendTransaction(signedTx) + assert.Nil(t, err) + + fmt.Printf("Created Tx: %s", signedTx.Hash().Hex()) + // make sure it's mined into a block within an acceptable time and avail in all nodes + fmt.Printf("Checking for tx receipt for %s", signedTx.Hash()) + var receipt *types.Receipt + for start := time.Now(); time.Since(start) < 30*time.Second; time.Sleep(time.Second) { + receipt, err = ethClient.TransactionReceipt(signedTx.Hash()) + if err == nil { + break + } + if !errors.Is(err, ethereum.NotFound) { + t.Fatal(err) + } + } + + if receipt == nil { + t.Fatalf("Did not mine the transaction after %s seconds - receipt: %+v", 30*time.Second, receipt) + } +} diff --git a/integration/eth2network/rotation_writer.go b/integration/eth2network/rotation_writer.go deleted file mode 100644 index b7b5b784d0..0000000000 --- a/integration/eth2network/rotation_writer.go +++ /dev/null @@ -1,122 +0,0 @@ -package eth2network - -import ( - "fmt" - "io" - "os" - "path/filepath" - "sort" - "time" -) - -type RotatingLogWriter struct { - dirPath string - fileStartName string - maxFileSize int64 - maxNumFiles int - currentFile *os.File - currentSize int64 - numFilesRotated int -} - -func NewRotatingLogWriter(dirPath, fileStartName string, maxFileSize int64, maxNumFiles int) (*RotatingLogWriter, error) { - writer := &RotatingLogWriter{ - dirPath: dirPath, - fileStartName: fileStartName, - maxFileSize: maxFileSize, - maxNumFiles: maxNumFiles, - } - - // Open the current log file - err := writer.openNextFile() - if err != nil { - return nil, err - } - - return writer, nil -} - -func (w *RotatingLogWriter) openNextFile() error { - if w.currentFile != nil { - err := w.currentFile.Close() - if err != nil { - fmt.Println(err) - } - } - - w.currentSize = 0 - w.numFilesRotated = 0 - - // Construct the file name for the next log file - timestamp := time.Now().Format("2006-01-02T15-04-05") - filename := w.fileStartName + "-" + timestamp + ".log" - filePath := filepath.Join(w.dirPath, filename) - - // Open the next log file - file, err := os.Create(filePath) - if err != nil { - return err - } - - w.currentFile = file - return nil -} - -func (w *RotatingLogWriter) Write(p []byte) (int, error) { - if w.currentFile == nil { - return 0, io.ErrClosedPipe - } - - // Rotate the log file if it exceeds the maximum file size - if w.currentSize+int64(len(p)) > w.maxFileSize { - err := w.rotateLogFile() - if err != nil { - return 0, err - } - } - - // Write the log message to the current log file - n, err := w.currentFile.Write(p) - w.currentSize += int64(n) - return n, err -} - -func (w *RotatingLogWriter) rotateLogFile() error { - err := w.openNextFile() - if err != nil { - return err - } - - w.numFilesRotated++ - - // Delete old log files if the maximum number of files has been exceeded - if w.maxNumFiles > 0 && w.numFilesRotated >= w.maxNumFiles { - err = w.deleteOldLogFiles() - if err != nil { - return err - } - } - - return nil -} - -func (w *RotatingLogWriter) deleteOldLogFiles() error { - // List all log files in the directory - files, err := filepath.Glob(filepath.Join(w.dirPath, w.fileStartName+"-*.log")) - if err != nil { - return err - } - - // Sort the log files by name (oldest first) - sort.Strings(files) - - // Delete the oldest log files - for i := 0; i < len(files)-w.maxNumFiles+1; i++ { - err := os.Remove(files[i]) - if err != nil { - return err - } - } - - return nil -} diff --git a/integration/eth2network/rotation_writer_test.go b/integration/eth2network/rotation_writer_test.go deleted file mode 100644 index f9748fe762..0000000000 --- a/integration/eth2network/rotation_writer_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package eth2network - -import ( - "math/rand" - "os" - "testing" - "time" - - "github.com/stretchr/testify/assert" -) - -func TestNewRotatingLogWriter(t *testing.T) { - temp, err := os.MkdirTemp("", "*") - assert.Nil(t, err) - - // Create a rotating log writer with a maximum size of 1 MB - writer, err := NewRotatingLogWriter(temp, "derp", 1024*1024, 5) - assert.Nil(t, err) - - createdFile := writer.currentFile.Name() - - // Use the rotating log writer with the standard log package - data := make([]byte, 1024*1024) - rand.Read(data) //nolint: gosec,staticcheck - _, err = writer.Write(data) - assert.Nil(t, err) - - // ensure the file name is different - time.Sleep(2 * time.Second) - - // Use the rotating log writer with the standard log package - rand.Read(data) //nolint: gosec,staticcheck - _, err = writer.Write(data) - assert.Nil(t, err) - - assert.NotEqual(t, createdFile, writer.currentFile.Name()) -} diff --git a/integration/eth2network/start-pos-network.sh b/integration/eth2network/start-pos-network.sh new file mode 100755 index 0000000000..96e7558d46 --- /dev/null +++ b/integration/eth2network/start-pos-network.sh @@ -0,0 +1,150 @@ +#!/usr/bin/env bash + +# Default port values +GETH_NETWORK_PORT=30303 +BEACON_P2P_PORT=12000 +GETH_HTTP_PORT=8025 +GETH_WS_PORT=9000 +GETH_RPC_PORT=8552 +BEACON_RPC_PORT=4000 +CHAIN_ID=1337 +BUILD_DIR="./build" +BASE_PATH="./" +GETH_BINARY="./geth" +BEACON_BINARY="./beacon-chain" +PRYSMCTL_BINARY="./prysmctl" +VALIDATOR_BINARY="./validator" +BEACON_LOG_FILE="./beacon-chain.log" +VALIDATOR_LOG_FILE="./validator.log" +GETH_LOG_FILE="./geth.log" +GETHDATA_DIR="/gethdata" +BEACONDATA_DIR="/beacondata" +VALIDATORDATA_DIR="/validatordata" + +# Function to display usage +usage() { + echo "Usage: $0 + [--geth-http GETH_HTTP_PORT] + [--geth-ws GETH_WS_PORT] + [--geth-rpc GETH_RPC_PORT] + [--beacon-rpc BEACON_RPC_PORT] + [--chainid CHAIN_ID ] + [--build-dir BUILD_DIR ] + [--base-path BASE_PATH ] + [--beacon-log BEACON_LOG_FILE] + [--validator-log VALIDATOR_LOG_FILE] + [--geth-log GETH_LOG_FILE] + [--geth-binary GETH_BINARY] + [--beacon-binary BEACON_BINARY] + [--prysmctl-binary PRYSMCTL_BINARY] + [--validator-binary VALIDATOR_BINARY] + [--gethdata-dir GETHDATA_DIR] + [--beacondata-dir BEACONDATA_DIR] + [--validatordata-dir VALIDATORDATA_DIR] " + exit 1 +} + +# Parse command-line arguments +while [[ "$#" -gt 0 ]]; do + case $1 in + --geth-network) GETH_NETWORK_PORT="$2"; shift ;; + --beacon-p2p) BEACON_P2P_PORT="$2"; shift ;; + --beacon-rpc) BEACON_RPC_PORT="$2"; shift ;; + --geth-http) GETH_HTTP_PORT="$2"; shift ;; + --geth-ws) GETH_WS_PORT="$2"; shift ;; + --geth-rpc) GETH_RPC_PORT="$2"; shift ;; + --chainid) CHAIN_ID="$2"; shift ;; + --build-dir) BUILD_DIR="$2"; shift ;; + --base-path) BASE_PATH="$2"; shift ;; + --geth-binary) GETH_BINARY="$2"; shift ;; + --beacon-binary) BEACON_BINARY="$2"; shift ;; + --prysmctl-binary) PRYSMCTL_BINARY="$2"; shift ;; + --validator-binary) VALIDATOR_BINARY="$2"; shift ;; + --beacon-log) BEACON_LOG_FILE="$2"; shift ;; + --validator-log) VALIDATOR_LOG_FILE="$2"; shift ;; + --geth-log) GETH_LOG_FILE="$2"; shift ;; + --gethdata-dir) GETHDATA_DIR="$2"; shift ;; + --beacondata-dir) BEACONDATA_DIR="$2"; shift ;; + --validatordata-dir) VALIDATORDATA_DIR="$2"; shift ;; + *) usage ;; + esac + shift +done + +mkdir -p "$(dirname "${BEACON_LOG_FILE}")" +mkdir -p "$(dirname "${VALIDATOR_LOG_FILE}")" +mkdir -p "$(dirname "${GETH_LOG_FILE}")" + +${PRYSMCTL_BINARY} testnet generate-genesis \ + --fork deneb \ + --num-validators 2 \ + --genesis-time-delay 5 \ + --chain-config-file "${BASE_PATH}/config.yml" \ + --geth-genesis-json-in "${BUILD_DIR}/genesis.json" \ + --geth-genesis-json-out "${BUILD_DIR}/genesis.json" \ + --output-ssz "${BEACONDATA_DIR}/genesis.ssz" + +sleep 1 +echo "Prysm genesis generated" + +echo -e "\n\n" | ${GETH_BINARY} --datadir="${GETHDATA_DIR}" account import "${BASE_PATH}/pk.txt" +echo "Private key imported into gethdata" + +${GETH_BINARY} --datadir="${GETHDATA_DIR}" init "${BUILD_DIR}/genesis.json" +sleep 1 +echo "Geth genesis initialized" + +# Run the Prysm beacon node +${BEACON_BINARY} --datadir="${BEACONDATA_DIR}" \ + --min-sync-peers 0 \ + --genesis-state "${BEACONDATA_DIR}/genesis.ssz" \ + --bootstrap-node= \ + --interop-eth1data-votes \ + --chain-config-file "${BASE_PATH}/config.yml" \ + --contract-deployment-block 0 \ + --chain-id "${CHAIN_ID}" \ + --rpc-host=127.0.0.1 \ + --rpc-port="${BEACON_RPC_PORT}" \ + --p2p-udp-port="${BEACON_P2P_PORT}" \ + --accept-terms-of-use \ + --jwt-secret "${BASE_PATH}/jwt.hex" \ + --suggested-fee-recipient 0x123463a4B065722E99115D6c222f267d9cABb524 \ + --minimum-peers-per-subnet 0 \ + --enable-debug-rpc-endpoints \ + --verbosity=debug \ + --execution-endpoint "${GETHDATA_DIR}/geth.ipc" > "${BEACON_LOG_FILE}" 2>&1 & +beacon_pid=$! +echo "BEACON PID $beacon_pid" + +# Run Prysm validator client +${VALIDATOR_BINARY} --beacon-rpc-provider=127.0.0.1:"${BEACON_RPC_PORT}" \ + --datadir="${VALIDATORDATA_DIR}" \ + --accept-terms-of-use \ + --interop-num-validators 2 \ + --chain-config-file "${BASE_PATH}/config.yml" > "${VALIDATOR_LOG_FILE}" 2>&1 & +validator_pid=$! +echo "VALIDATOR PID $validator_pid" + +# Run go-ethereum +${GETH_BINARY} --http \ + --http.api eth,net,web3,debug \ + --http.addr="0.0.0.0" \ + --http.port="${GETH_HTTP_PORT}" \ + --http.corsdomain "*" \ + --http.vhosts "*" \ + --ws --ws.api eth,net,web3,debug \ + --ws.addr="0.0.0.0" \ + --ws.port="${GETH_WS_PORT}" \ + --ws.origins "*" \ + --authrpc.jwtsecret "${BASE_PATH}/jwt.hex" \ + --authrpc.port "${GETH_RPC_PORT}" \ + --port="${GETH_NETWORK_PORT}" \ + --datadir="${GETHDATA_DIR}" \ + --networkid="${CHAIN_ID}" \ + --nodiscover \ + --syncmode full \ + --allow-insecure-unlock \ + --unlock 0x123463a4b065722e99115d6c222f267d9cabb524 \ + --password "${BASE_PATH}/password.txt" > "${GETH_LOG_FILE}" 2>&1 & +geth_pid=$! +echo "GETH PID $geth_pid" \ No newline at end of file diff --git a/integration/noderunner/noderunner_test.go b/integration/noderunner/noderunner_test.go index e2e872b034..ff25cf8434 100644 --- a/integration/noderunner/noderunner_test.go +++ b/integration/noderunner/noderunner_test.go @@ -1,14 +1,12 @@ package noderunner import ( - "encoding/hex" "fmt" "net/http" "testing" "time" "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/ethereum/go-ethereum/crypto" "github.com/ten-protocol/go-ten/go/common/profiler" "github.com/ten-protocol/go-ten/go/node" "github.com/ten-protocol/go-ten/go/rpc" @@ -16,7 +14,6 @@ import ( "github.com/ten-protocol/go-ten/integration/common/testlog" "github.com/ten-protocol/go-ten/integration/eth2network" - gethcommon "github.com/ethereum/go-ethereum/common" gethlog "github.com/ethereum/go-ethereum/log" ) @@ -26,8 +23,8 @@ const ( _startPort = integration.StartPortNodeRunnerTest ) -// A smoke test to check that we can stand up a standalone Obscuro host and enclave. -func TestCanStartStandaloneObscuroHostAndEnclave(t *testing.T) { +// A smoke test to check that we can stand up a standalone Ten host and enclave. +func TestCanStartStandaloneTenHostAndEnclave(t *testing.T) { testlog.Setup(&testlog.Cfg{ LogDir: _testLogs, TestType: "noderunner", @@ -36,31 +33,27 @@ func TestCanStartStandaloneObscuroHostAndEnclave(t *testing.T) { }) // todo run the noderunner test with different obscuro node instances - newNode, hostAddr := createInMemoryNode(t) + newNode := createInMemoryNode() - binariesPath, err := eth2network.EnsureBinariesExist() + binDir, err := eth2network.EnsureBinariesExist() if err != nil { panic(err) } - network := eth2network.NewEth2Network( - binariesPath, - true, - _startPort, - _startPort+integration.DefaultGethWSPortOffset, - _startPort+integration.DefaultGethAUTHPortOffset, + network := eth2network.NewPosEth2Network( + binDir, _startPort+integration.DefaultGethNetworkPortOffset, - _startPort+integration.DefaultPrysmHTTPPortOffset, _startPort+integration.DefaultPrysmP2PPortOffset, - 1337, - 1, - 1, - 2, - 2, - []string{hostAddr.String()}, - 2*time.Minute, + _startPort+integration.DefaultGethAUTHPortOffset, + _startPort+integration.DefaultGethWSPortOffset, + _startPort+integration.DefaultGethHTTPPortOffset, + _startPort+integration.DefaultPrysmRPCPortOffset, + integration.EthereumChainID, + 3*time.Minute, ) + defer network.Stop() //nolint: errcheck + err = network.Start() if err != nil { panic(err) @@ -73,10 +66,10 @@ func TestCanStartStandaloneObscuroHostAndEnclave(t *testing.T) { // we create the node RPC client wsURL := fmt.Sprintf("ws://127.0.0.1:%d", _startPort+integration.DefaultGethWSPortOffset) - var obscuroClient rpc.Client + var tenClient rpc.Client wait := 30 // max wait in seconds for { - obscuroClient, err = rpc.NewNetworkClient(wsURL) + tenClient, err = rpc.NewNetworkClient(wsURL) if err == nil { break } @@ -106,7 +99,7 @@ func TestCanStartStandaloneObscuroHostAndEnclave(t *testing.T) { time.Sleep(time.Second) var rollupNumber hexutil.Uint64 - err = obscuroClient.Call(&rollupNumber, rpc.BatchNumber) + err = tenClient.Call(&rollupNumber, rpc.BatchNumber) if err == nil && rollupNumber > 0 { return } @@ -115,16 +108,10 @@ func TestCanStartStandaloneObscuroHostAndEnclave(t *testing.T) { t.Fatalf("Zero rollups have been produced after ten seconds. Something is wrong. Latest error was: %s", err) } -func createInMemoryNode(t *testing.T) (node.Node, gethcommon.Address) { - privateKey, err := crypto.GenerateKey() - if err != nil { - t.Fatal(err) - } - hostAddress := crypto.PubkeyToAddress(privateKey.PublicKey) - +func createInMemoryNode() node.Node { nodeCfg := node.NewNodeConfig( - node.WithPrivateKey(hex.EncodeToString(crypto.FromECDSA(privateKey))), - node.WithHostID(hostAddress.String()), + node.WithPrivateKey(integration.GethNodePK), + node.WithHostID(integration.GethNodeAddress), node.WithEnclaveWSPort(_startPort+integration.DefaultEnclaveOffset), node.WithHostHTTPPort(_startPort+integration.DefaultHostRPCHTTPOffset), node.WithHostWSPort(_startPort+integration.DefaultHostRPCWSOffset), @@ -134,5 +121,5 @@ func createInMemoryNode(t *testing.T) (node.Node, gethcommon.Address) { node.WithL1BlockTime(1*time.Second), ) - return NewInMemNode(nodeCfg), hostAddress + return NewInMemNode(nodeCfg) } diff --git a/integration/simulation/devnetwork/dev_network.go b/integration/simulation/devnetwork/dev_network.go index 2315393403..562235314b 100644 --- a/integration/simulation/devnetwork/dev_network.go +++ b/integration/simulation/devnetwork/dev_network.go @@ -36,7 +36,7 @@ const ( var _defaultFaucetAmount = big.NewInt(750_000_000_000_000) -// InMemDevNetwork is a local dev network (L1 and L2) - the obscuro nodes are in-memory in a single go process, the L1 nodes are a docker geth network +// InMemDevNetwork is a local dev network (L1 and L2) - the Ten nodes are in-memory in a single go process, the L1 nodes are a docker geth network // // It can play the role of node operators and network admins to reproduce complex scenarios around nodes joining/leaving/failing. // @@ -50,9 +50,9 @@ type InMemDevNetwork struct { l1Network L1Network - // When Obscuro network has been initialised on the L1 network, this will be populated + // When Ten network has been initialised on the L1 network, this will be populated // - if reconnecting to an existing network it needs to be populated when initialising this object - // - if it is nil when `Start()` is called then Obscuro contracts will be deployed on the L1 + // - if it is nil when `Start()` is called then Ten contracts will be deployed on the L1 l1SetupData *params.L1TenData tenConfig *TenConfig @@ -148,10 +148,10 @@ func (s *InMemDevNetwork) Start() { s.l1Network.Prepare() if s.l1SetupData == nil { // this is a new network, deploy the contracts to the L1 - fmt.Println("Deploying obscuro contracts to L1") - s.deployObscuroNetworkContracts() + fmt.Println("Deploying Ten contracts to L1") + s.deployTenNetworkContracts() } - fmt.Println("Starting obscuro nodes") + fmt.Println("Starting Ten nodes") s.startNodes() // sleep to allow the nodes to start @@ -253,10 +253,10 @@ func (s *InMemDevNetwork) CleanUp() { time.Sleep(3 * time.Second) } -func (s *InMemDevNetwork) deployObscuroNetworkContracts() { +func (s *InMemDevNetwork) deployTenNetworkContracts() { client := s.l1Network.GetClient(0) // note: we don't currently deploy ERC20s here, don't want to waste gas on sepolia - l1SetupData, err := network.DeployObscuroNetworkContracts(client, s.networkWallets, false) + l1SetupData, err := network.DeployTenNetworkContracts(client, s.networkWallets, false) if err != nil { panic(err) } diff --git a/integration/simulation/devnetwork/geth_l1.go b/integration/simulation/devnetwork/geth_l1.go index c78376bfad..3eae7a6518 100644 --- a/integration/simulation/devnetwork/geth_l1.go +++ b/integration/simulation/devnetwork/geth_l1.go @@ -16,7 +16,7 @@ type gethDockerNetwork struct { networkWallets *params.SimWallets l1Config *L1Config l1Clients []ethadapter.EthClient - ethNetwork eth2network.Eth2Network + ethNetwork eth2network.PosEth2Network } func NewGethNetwork(networkWallets *params.SimWallets, l1Config *L1Config) L1Network { @@ -27,7 +27,7 @@ func NewGethNetwork(networkWallets *params.SimWallets, l1Config *L1Config) L1Net } func (g *gethDockerNetwork) Prepare() { - gethNetwork, err := network.StartGethNetwork(g.networkWallets, g.l1Config.PortStart, int(g.l1Config.AvgBlockDuration.Seconds())) + gethNetwork, err := network.StartGethNetwork(g.networkWallets, g.l1Config.PortStart) if err != nil { panic(err) } diff --git a/integration/simulation/network/geth_network.go b/integration/simulation/network/geth_network.go index c40deede97..b1564b9068 100644 --- a/integration/simulation/network/geth_network.go +++ b/integration/simulation/network/geth_network.go @@ -16,7 +16,7 @@ type networkInMemGeth struct { l2Clients []rpc.Client // geth - eth2Network eth2network.Eth2Network + eth2Network eth2network.PosEth2Network gethClients []ethadapter.EthClient wallets *params.SimWallets } @@ -34,33 +34,32 @@ func (n *networkInMemGeth) Create(params *params.SimParams, _ *stats.Stats) (*RP n.wallets, params.StartPort, params.NumberOfNodes, - int(params.AvgBlockDuration.Seconds()), ) params.MgmtContractLib = mgmtcontractlib.NewMgmtContractLib(¶ms.L1TenData.MgmtContractAddress, testlog.Logger()) params.ERC20ContractLib = erc20contractlib.NewERC20ContractLib(¶ms.L1TenData.MgmtContractAddress, ¶ms.L1TenData.ObxErc20Address, ¶ms.L1TenData.EthErc20Address) - // Start the obscuro nodes and return the handles - n.l2Clients = startInMemoryObscuroNodes(params, n.eth2Network.GethGenesis(), n.gethClients) + // Start the ten nodes and return the handles + n.l2Clients = startInMemoryTenNodes(params, n.eth2Network.GenesisBytes(), n.gethClients) - obscuroClients := make([]*obsclient.ObsClient, params.NumberOfNodes) + tenClients := make([]*obsclient.ObsClient, params.NumberOfNodes) for idx, l2Client := range n.l2Clients { - obscuroClients[idx] = obsclient.NewObsClient(l2Client) + tenClients[idx] = obsclient.NewObsClient(l2Client) } walletClients := createAuthClientsPerWallet(n.l2Clients, params.Wallets) return &RPCHandles{ EthClients: n.gethClients, - ObscuroClients: obscuroClients, + TenClients: tenClients, RPCClients: n.l2Clients, AuthObsClients: walletClients, }, nil } func (n *networkInMemGeth) TearDown() { - // Stop the obscuro nodes first - StopObscuroNodes(n.l2Clients) + // Stop the Ten nodes first + StopTenNodes(n.l2Clients) // Stop geth last StopEth2Network(n.gethClients, n.eth2Network) diff --git a/integration/simulation/network/geth_utils.go b/integration/simulation/network/geth_utils.go index a8df58c26d..bd0a247286 100644 --- a/integration/simulation/network/geth_utils.go +++ b/integration/simulation/network/geth_utils.go @@ -22,14 +22,8 @@ import ( "github.com/ten-protocol/go-ten/integration/simulation/params" ) -const ( - // These are the addresses that the end-to-end tests expect to be prefunded when run locally. Corresponds to - // private key hex "f52e5418e349dccdda29b6ac8b0abe6576bb7713886aa85abea6181ba731f9bb". - e2eTestPrefundedL1Addr = "0x13E23Ca74DE0206C56ebaE8D51b5622EFF1E9944" -) - -func SetUpGethNetwork(wallets *params.SimWallets, startPort int, nrNodes int, blockDurationSeconds int) (*params.L1TenData, []ethadapter.EthClient, eth2network.Eth2Network) { - eth2Network, err := StartGethNetwork(wallets, startPort, blockDurationSeconds) +func SetUpGethNetwork(wallets *params.SimWallets, startPort int, nrNodes int) (*params.L1TenData, []ethadapter.EthClient, eth2network.PosEth2Network) { + eth2Network, err := StartGethNetwork(wallets, startPort) if err != nil { panic(fmt.Errorf("error starting geth network %w", err)) } @@ -40,7 +34,7 @@ func SetUpGethNetwork(wallets *params.SimWallets, startPort int, nrNodes int, bl panic(fmt.Errorf("error connecting to te first host %w", err)) } - l1Data, err := DeployObscuroNetworkContracts(tmpEthClient, wallets, true) + l1Data, err := DeployTenNetworkContracts(tmpEthClient, wallets, true) if err != nil { panic(fmt.Errorf("error deploying obscuro contract %w", err)) } @@ -53,49 +47,41 @@ func SetUpGethNetwork(wallets *params.SimWallets, startPort int, nrNodes int, bl return l1Data, ethClients, eth2Network } -func StartGethNetwork(wallets *params.SimWallets, startPort int, blockDurationSeconds int) (eth2network.Eth2Network, error) { +func StartGethNetwork(wallets *params.SimWallets, startPort int) (eth2network.PosEth2Network, error) { // make sure the geth network binaries exist - path, err := eth2network.EnsureBinariesExist() + binDir, err := eth2network.EnsureBinariesExist() if err != nil { return nil, err } // get the node wallet addresses to prefund them with Eth, so they can submit rollups, deploy contracts, deposit to the bridge, etc - walletAddresses := []string{e2eTestPrefundedL1Addr} + walletAddresses := []string{integration.GethNodeAddress} for _, w := range wallets.AllEthWallets() { walletAddresses = append(walletAddresses, w.Address().String()) } - fmt.Printf("Prefunded wallet addresses: %d\n", len(walletAddresses)) - - // kickoff the network with the prefunded wallet addresses - eth2Network := eth2network.NewEth2Network( - path, - true, - startPort, - startPort+integration.DefaultGethWSPortOffset, - startPort+integration.DefaultGethAUTHPortOffset, + network := eth2network.NewPosEth2Network( + binDir, startPort+integration.DefaultGethNetworkPortOffset, - startPort+integration.DefaultPrysmHTTPPortOffset, startPort+integration.DefaultPrysmP2PPortOffset, - 1337, - 1, - blockDurationSeconds, - 2, - 2, - walletAddresses, - 2*time.Minute, + startPort+integration.DefaultGethAUTHPortOffset, // RPC + startPort+integration.DefaultGethWSPortOffset, + startPort+integration.DefaultGethHTTPPortOffset, + startPort+integration.DefaultPrysmRPCPortOffset, // RPC + integration.EthereumChainID, + 6*time.Minute, + walletAddresses..., ) - err = eth2Network.Start() + err = network.Start() if err != nil { return nil, err } - return eth2Network, nil + return network, nil } -func DeployObscuroNetworkContracts(client ethadapter.EthClient, wallets *params.SimWallets, deployERC20s bool) (*params.L1TenData, error) { +func DeployTenNetworkContracts(client ethadapter.EthClient, wallets *params.SimWallets, deployERC20s bool) (*params.L1TenData, error) { bytecode, err := constants.Bytecode() if err != nil { return nil, err @@ -161,7 +147,7 @@ func DeployObscuroNetworkContracts(client ethadapter.EthClient, wallets *params. }, nil } -func StopEth2Network(clients []ethadapter.EthClient, netw eth2network.Eth2Network) { +func StopEth2Network(clients []ethadapter.EthClient, network eth2network.PosEth2Network) { // Stop the clients first for _, c := range clients { if c != nil { @@ -169,8 +155,8 @@ func StopEth2Network(clients []ethadapter.EthClient, netw eth2network.Eth2Networ } } // Stop the nodes second - if netw != nil { // If network creation failed, we may be attempting to tear down the Geth network before it even exists. - err := netw.Stop() + if network != nil { // If network creation failed, we may be attempting to tear down the Geth network before it even exists. + err := network.Stop() if err != nil { fmt.Println(err) } diff --git a/integration/simulation/network/inmemory.go b/integration/simulation/network/inmemory.go index 12c37f4d7b..79b162c19e 100644 --- a/integration/simulation/network/inmemory.go +++ b/integration/simulation/network/inmemory.go @@ -30,9 +30,9 @@ func NewBasicNetworkOfInMemoryNodes() Network { func (n *basicNetworkOfInMemoryNodes) Create(params *params.SimParams, stats *stats.Stats) (*RPCHandles, error) { l1Clients := make([]ethadapter.EthClient, params.NumberOfNodes) n.ethNodes = make([]*ethereummock.Node, params.NumberOfNodes) - obscuroNodes := make([]*container.HostContainer, params.NumberOfNodes) + tenNodes := make([]*container.HostContainer, params.NumberOfNodes) n.l2Clients = make([]rpc.Client, params.NumberOfNodes) - obscuroHosts := make([]host.Host, params.NumberOfNodes) + tenHosts := make([]host.Host, params.NumberOfNodes) p2pNetw := p2p.NewMockP2PNetwork(params.AvgBlockDuration, params.AvgNetworkLatency, params.NodeWithInboundP2PDisabled) @@ -53,7 +53,7 @@ func (n *basicNetworkOfInMemoryNodes) Create(params *params.SimParams, stats *st // create the in memory l1 and l2 node miner := createMockEthNode(int64(i), params.NumberOfNodes, params.AvgBlockDuration, params.AvgNetworkLatency, stats) - agg := createInMemObscuroNode( + agg := createInMemTenNode( int64(i), isGenesis, GetNodeType(i), @@ -69,13 +69,13 @@ func (n *basicNetworkOfInMemoryNodes) Create(params *params.SimParams, stats *st incomingP2PDisabled, params.AvgBlockDuration, ) - obscuroClient := p2p.NewInMemObscuroClient(agg) + tenClient := p2p.NewInMemTenClient(agg) n.ethNodes[i] = miner - obscuroNodes[i] = agg - n.l2Clients[i] = obscuroClient + tenNodes[i] = agg + n.l2Clients[i] = tenClient l1Clients[i] = miner - obscuroHosts[i] = obscuroNodes[i].Host() + tenHosts[i] = tenNodes[i].Host() } // populate the nodes field of each network @@ -86,8 +86,8 @@ func (n *basicNetworkOfInMemoryNodes) Create(params *params.SimParams, stats *st // The sequence of starting the nodes is important to catch various edge cases. // Here we first start the mock layer 1 nodes, with a pause between them of a fraction of a block duration. // The reason is to make sure that they catch up correctly. - // Then we pause for a while, to give the L1 network enough time to create a number of blocks, which will have to be ingested by the Obscuro nodes - // Then, we begin the starting sequence of the Obscuro nodes, again with a delay between them, to test that they are able to cach up correctly. + // Then we pause for a while, to give the L1 network enough time to create a number of blocks, which will have to be ingested by the en nodes + // Then, we begin the starting sequence of the Ten nodes, again with a delay between them, to test that they are able to cach up correctly. // Note: Other simulations might test variations of this pattern. for _, m := range n.ethNodes { t := m @@ -95,7 +95,7 @@ func (n *basicNetworkOfInMemoryNodes) Create(params *params.SimParams, stats *st time.Sleep(params.AvgBlockDuration) } - for _, m := range obscuroNodes { + for _, m := range tenNodes { t := m go func() { err := t.Start() @@ -106,22 +106,22 @@ func (n *basicNetworkOfInMemoryNodes) Create(params *params.SimParams, stats *st time.Sleep(params.AvgBlockDuration / 3) } - obscuroClients := make([]*obsclient.ObsClient, params.NumberOfNodes) + tenClients := make([]*obsclient.ObsClient, params.NumberOfNodes) for idx, l2Client := range n.l2Clients { - obscuroClients[idx] = obsclient.NewObsClient(l2Client) + tenClients[idx] = obsclient.NewObsClient(l2Client) } walletClients := createAuthClientsPerWallet(n.l2Clients, params.Wallets) return &RPCHandles{ EthClients: l1Clients, - ObscuroClients: obscuroClients, + TenClients: tenClients, RPCClients: n.l2Clients, AuthObsClients: walletClients, }, nil } func (n *basicNetworkOfInMemoryNodes) TearDown() { - StopObscuroNodes(n.l2Clients) + StopTenNodes(n.l2Clients) for _, node := range n.ethNodes { temp := node diff --git a/integration/simulation/network/network.go b/integration/simulation/network/network.go index b1f05b0c11..15bd804b9e 100644 --- a/integration/simulation/network/network.go +++ b/integration/simulation/network/network.go @@ -15,15 +15,15 @@ import ( "github.com/ten-protocol/go-ten/integration/simulation/stats" ) -// Network is responsible with knowing how to manage the lifecycle of networks of Ethereum or Obscuro nodes. +// Network is responsible with knowing how to manage the lifecycle of networks of Ethereum or Ten nodes. // These networks can be composed of in-memory go-routines or of fully fledged existing nodes like Ropsten. // Implementation notes: // - This is a work in progress, so there is a lot of code duplication in the implementations // - Once we implement a few more versions: for example using Geth, we'll revisit and create better abstractions. type Network interface { - // Create - returns the started Ethereum nodes and the started Obscuro node clients. + // Create - returns the started Ethereum nodes and the started Ten node clients. // Responsible with spinning up all resources required for the test - // Return an error in case it cannot start for an expected reason. Otherwise it panics. + // Return an error in case it cannot start for an expected reason, otherwise it panics. Create(params *params.SimParams, stats *stats.Stats) (*RPCHandles, error) TearDown() } @@ -32,9 +32,9 @@ type RPCHandles struct { // an eth client per eth node in the network EthClients []ethadapter.EthClient - // An Obscuro client per Obscuro node in the network. - ObscuroClients []*obsclient.ObsClient - // An RPC client per Obscuro node in the network (used for APIs that don't have methods on `ObsClient`. + // A Ten client per Ten node in the network. + TenClients []*obsclient.ObsClient + // An RPC client per Ten node in the network (used for APIs that don't have methods on `ObsClient`. RPCClients []rpc.Client // an RPC client per node per wallet, with a viewing key set up (on the client and registered on its corresponding host enclave), @@ -48,15 +48,15 @@ func (n *RPCHandles) RndEthClient() ethadapter.EthClient { return n.EthClients[rand.Intn(len(n.EthClients))] //nolint:gosec } -// ObscuroWalletRndClient fetches an RPC client connected to a random L2 node for a given wallet -func (n *RPCHandles) ObscuroWalletRndClient(wallet wallet.Wallet) *obsclient.AuthObsClient { +// TenWalletRndClient fetches an RPC client connected to a random L2 node for a given wallet +func (n *RPCHandles) TenWalletRndClient(wallet wallet.Wallet) *obsclient.AuthObsClient { addr := wallet.Address().String() clients := n.AuthObsClients[addr] return clients[rand.Intn(len(clients))] //nolint:gosec } -// ObscuroWalletClient fetches a client for a given wallet address, for a specific node -func (n *RPCHandles) ObscuroWalletClient(walletAddress common.Address, nodeIdx int) *obsclient.AuthObsClient { +// TenWalletClient fetches a client for a given wallet address, for a specific node +func (n *RPCHandles) TenWalletClient(walletAddress common.Address, nodeIdx int) *obsclient.AuthObsClient { clients := n.AuthObsClients[walletAddress.String()] return clients[nodeIdx] } diff --git a/integration/simulation/network/network_utils.go b/integration/simulation/network/network_utils.go index b760bb4176..5ee9a2204b 100644 --- a/integration/simulation/network/network_utils.go +++ b/integration/simulation/network/network_utils.go @@ -45,7 +45,7 @@ func createMockEthNode(id int64, nrNodes int, avgBlockDuration time.Duration, av return miner } -func createInMemObscuroNode( +func createInMemTenNode( id int64, isGenesis bool, nodeType common.NodeType, @@ -102,7 +102,7 @@ func createInMemObscuroNode( enclaveLogger := testlog.Logger().New(log.NodeIDKey, id, log.CmpKey, log.EnclaveCmp) enclaveClients := []common.Enclave{enclave.NewEnclave(enclaveConfig, &genesis.TestnetGenesis, mgmtContractLib, enclaveLogger)} - // create an in memory obscuro node + // create an in memory Ten node hostLogger := testlog.Logger().New(log.NodeIDKey, id, log.CmpKey, log.HostCmp) metricsService := metrics.New(hostConfig.MetricsEnabled, hostConfig.MetricsHTTPPort, hostLogger) l1Repo := l1.NewL1Repository(ethClient, ethereummock.MgmtContractAddresses, hostLogger) diff --git a/integration/simulation/network/obscuro_node_utils.go b/integration/simulation/network/obscuro_node_utils.go index ec3fcff229..36f62690b4 100644 --- a/integration/simulation/network/obscuro_node_utils.go +++ b/integration/simulation/network/obscuro_node_utils.go @@ -29,16 +29,16 @@ const ( networkTCP = "tcp" ) -func startInMemoryObscuroNodes(params *params.SimParams, genesisJSON []byte, l1Clients []ethadapter.EthClient) []rpc.Client { - // Create the in memory obscuro nodes, each connect each to a geth node - obscuroNodes := make([]*hostcontainer.HostContainer, params.NumberOfNodes) - obscuroHosts := make([]host.Host, params.NumberOfNodes) +func startInMemoryTenNodes(params *params.SimParams, genesisJSON []byte, l1Clients []ethadapter.EthClient) []rpc.Client { + // Create the in memory ten nodes, each connect each to a geth node + tenNodes := make([]*hostcontainer.HostContainer, params.NumberOfNodes) + tenHosts := make([]host.Host, params.NumberOfNodes) mockP2PNetw := p2p.NewMockP2PNetwork(params.AvgBlockDuration, params.AvgNetworkLatency, params.NodeWithInboundP2PDisabled) for i := 0; i < params.NumberOfNodes; i++ { isGenesis := i == 0 - obscuroNodes[i] = createInMemObscuroNode( + tenNodes[i] = createInMemTenNode( int64(i), isGenesis, GetNodeType(i), @@ -54,11 +54,11 @@ func startInMemoryObscuroNodes(params *params.SimParams, genesisJSON []byte, l1C true, params.AvgBlockDuration, ) - obscuroHosts[i] = obscuroNodes[i].Host() + tenHosts[i] = tenNodes[i].Host() } - // start each obscuro node - for _, m := range obscuroNodes { + // start each ten node + for _, m := range tenNodes { t := m go func() { err := t.Start() @@ -69,13 +69,13 @@ func startInMemoryObscuroNodes(params *params.SimParams, genesisJSON []byte, l1C } // Create a handle to each node - obscuroClients := make([]rpc.Client, params.NumberOfNodes) - for i, node := range obscuroNodes { - obscuroClients[i] = p2p.NewInMemObscuroClient(node) + tenClients := make([]rpc.Client, params.NumberOfNodes) + for i, node := range tenNodes { + tenClients[i] = p2p.NewInMemTenClient(node) } time.Sleep(100 * time.Millisecond) - return obscuroClients + return tenClients } func createAuthClientsPerWallet(clients []rpc.Client, wallets *params.SimWallets) map[string][]*obsclient.AuthObsClient { @@ -108,8 +108,8 @@ func CreateAuthClients(clients []rpc.Client, wal wallet.Wallet) []*obsclient.Aut return authClients } -// StopObscuroNodes stops the Obscuro nodes and their RPC clients. -func StopObscuroNodes(clients []rpc.Client) { +// StopTenNodes stops the Ten nodes and their RPC clients. +func StopTenNodes(clients []rpc.Client) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() eg, _ := errgroup.WithContext(ctx) @@ -119,7 +119,7 @@ func StopObscuroNodes(clients []rpc.Client) { eg.Go(func() error { err := c.Call(nil, rpc.StopHost) if err != nil { - testlog.Logger().Error("Could not stop Obscuro node.", log.ErrKey, err) + testlog.Logger().Error("Could not stop Ten node.", log.ErrKey, err) return err } c.Stop() @@ -129,10 +129,10 @@ func StopObscuroNodes(clients []rpc.Client) { err := eg.Wait() if err != nil { - testlog.Logger().Error(fmt.Sprintf("Error waiting for the Obscuro nodes to stop - %s", err)) + testlog.Logger().Error(fmt.Sprintf("Error waiting for the Ten nodes to stop - %s", err)) } - testlog.Logger().Info("Obscuro nodes stopped") + testlog.Logger().Info("Ten nodes stopped") } // CheckHostRPCServersStopped checks whether the hosts' RPC server addresses have been freed up. @@ -157,10 +157,10 @@ func CheckHostRPCServersStopped(hostWSURLS []string) { err := eg.Wait() if err != nil { - panic(fmt.Sprintf("Timed out waiting for the Obscuro host RPC addresses to become available - %s", err)) + panic(fmt.Sprintf("Timed out waiting for the Ten host RPC addresses to become available - %s", err)) } - testlog.Logger().Info("Obscuro host RPC addresses freed") + testlog.Logger().Info("Ten host RPC addresses freed") } func isAddressAvailable(address string) bool { diff --git a/integration/simulation/network/socket.go b/integration/simulation/network/socket.go index f3e1765e5e..3f8ecf64b2 100644 --- a/integration/simulation/network/socket.go +++ b/integration/simulation/network/socket.go @@ -25,16 +25,16 @@ import ( "github.com/ten-protocol/go-ten/integration/simulation/stats" ) -// creates Obscuro nodes with their own enclave servers that communicate with peers via sockets, wires them up, and populates the network objects +// creates Ten nodes with their own enclave servers that communicate with peers via sockets, wires them up, and populates the network objects type networkOfSocketNodes struct { l2Clients []rpc.Client hostWebsocketURLs []string // geth - eth2Network eth2network.Eth2Network - gethClients []ethadapter.EthClient - wallets *params.SimWallets - obscuroClients []*obsclient.ObsClient + eth2Network eth2network.PosEth2Network + gethClients []ethadapter.EthClient + wallets *params.SimWallets + tenClients []*obsclient.ObsClient } func NewNetworkOfSocketNodes(wallets *params.SimWallets) Network { @@ -49,7 +49,6 @@ func (n *networkOfSocketNodes) Create(simParams *params.SimParams, _ *stats.Stat n.wallets, simParams.StartPort, simParams.NumberOfNodes, - int(simParams.AvgBlockDuration.Seconds()), ) simParams.MgmtContractLib = mgmtcontractlib.NewMgmtContractLib(&simParams.L1TenData.MgmtContractAddress, testlog.Logger()) @@ -109,7 +108,7 @@ func (n *networkOfSocketNodes) Create(simParams *params.SimParams, _ *stats.Stat node.WithLogLevel(4), node.WithDebugNamespaceEnabled(true), node.WithL1BlockTime(simParams.AvgBlockDuration), - node.WithObscuroGenesis(genesis), + node.WithTenGenesis(genesis), ), ) @@ -120,8 +119,8 @@ func (n *networkOfSocketNodes) Create(simParams *params.SimParams, _ *stats.Stat if errCheck != nil { testlog.Logger().Warn("no port found on error", log.ErrKey, err) } - fmt.Printf("unable to start obscuro node: %s", err) - testlog.Logger().Error("unable to start obscuro node ", log.ErrKey, err) + fmt.Printf("unable to start Ten node: %s", err) + testlog.Logger().Error("unable to start Ten node ", log.ErrKey, err) } } @@ -134,15 +133,15 @@ func (n *networkOfSocketNodes) Create(simParams *params.SimParams, _ *stats.Stat return &RPCHandles{ EthClients: n.gethClients, - ObscuroClients: n.obscuroClients, + TenClients: n.tenClients, RPCClients: n.l2Clients, AuthObsClients: walletClients, }, nil } func (n *networkOfSocketNodes) TearDown() { - // Stop the Obscuro nodes first (each host will attempt to shut down its enclave as part of shutdown). - StopObscuroNodes(n.l2Clients) + // Stop the Ten nodes first (each host will attempt to shut down its enclave as part of shutdown). + StopTenNodes(n.l2Clients) StopEth2Network(n.gethClients, n.eth2Network) CheckHostRPCServersStopped(n.hostWebsocketURLs) } @@ -151,7 +150,7 @@ func (n *networkOfSocketNodes) createConnections(simParams *params.SimParams) er // create the clients in the structs n.l2Clients = make([]rpc.Client, simParams.NumberOfNodes) n.hostWebsocketURLs = make([]string, simParams.NumberOfNodes) - n.obscuroClients = make([]*obsclient.ObsClient, simParams.NumberOfNodes) + n.tenClients = make([]*obsclient.ObsClient, simParams.NumberOfNodes) for i := 0; i < simParams.NumberOfNodes; i++ { var client rpc.Client @@ -175,11 +174,11 @@ func (n *networkOfSocketNodes) createConnections(simParams *params.SimParams) er } for idx, l2Client := range n.l2Clients { - n.obscuroClients[idx] = obsclient.NewObsClient(l2Client) + n.tenClients[idx] = obsclient.NewObsClient(l2Client) } // make sure the nodes are healthy - for _, client := range n.obscuroClients { + for _, client := range n.tenClients { startTime := time.Now() healthy := false for ; !healthy; time.Sleep(500 * time.Millisecond) { diff --git a/integration/simulation/output_stats.go b/integration/simulation/output_stats.go index cf7a75a72b..27f652cec2 100644 --- a/integration/simulation/output_stats.go +++ b/integration/simulation/output_stats.go @@ -47,8 +47,8 @@ func (o *OutputStats) populateHeights() { } o.l1Height = int(l1Height) - obscuroClient := o.simulation.RPCHandles.ObscuroClients[0] - hRollup, err := getHeadBatchHeader(obscuroClient) + tenClient := o.simulation.RPCHandles.TenClients[0] + hRollup, err := getHeadBatchHeader(tenClient) if err != nil { panic(err) } @@ -58,10 +58,10 @@ func (o *OutputStats) populateHeights() { func (o *OutputStats) countBlockChain() { l1Node := o.simulation.RPCHandles.EthClients[0] - obscuroClient := o.simulation.RPCHandles.ObscuroClients[0] + tenClient := o.simulation.RPCHandles.TenClients[0] // iterate the Node Headers and get the rollups - header, err := getHeadBatchHeader(obscuroClient) + header, err := getHeadBatchHeader(tenClient) if err != nil { panic(err) } @@ -73,7 +73,7 @@ func (o *OutputStats) countBlockChain() { o.l2RollupCountInHeaders++ - header, err = obscuroClient.GetBatchHeaderByHash(header.ParentHash) + header, err = tenClient.GetBatchHeaderByHash(header.ParentHash) if err != nil { testlog.Logger().Crit("could not retrieve rollup by hash.", log.ErrKey, err) } diff --git a/integration/simulation/p2p/in_mem_obscuro_client.go b/integration/simulation/p2p/in_mem_obscuro_client.go index 0c4f51be6e..71d002a43b 100644 --- a/integration/simulation/p2p/in_mem_obscuro_client.go +++ b/integration/simulation/p2p/in_mem_obscuro_client.go @@ -29,8 +29,8 @@ const ( // todo - move this from the P2P folder // An in-memory implementation of `rpc.Client` that speaks directly to the node. -type inMemObscuroClient struct { - obscuroAPI *clientapi.ObscuroAPI +type inMemTenClient struct { + tenAPI *clientapi.TenAPI ethAPI *clientapi.EthereumAPI filterAPI *clientapi.FilterAPI tenScanAPI *clientapi.ScanAPI @@ -38,7 +38,7 @@ type inMemObscuroClient struct { enclavePublicKey *ecies.PublicKey } -func NewInMemObscuroClient(hostContainer *container.HostContainer) rpc.Client { +func NewInMemTenClient(hostContainer *container.HostContainer) rpc.Client { logger := testlog.Logger().New(log.CmpKey, log.RPCClientCmp) // todo: this is a convenience for testnet but needs to replaced by a parameter and/or retrieved from the target host enclPubECDSA, err := crypto.DecompressPubkey(gethcommon.Hex2Bytes(enclavePublicKeyHex)) @@ -47,8 +47,8 @@ func NewInMemObscuroClient(hostContainer *container.HostContainer) rpc.Client { } enclPubKey := ecies.ImportECDSAPublic(enclPubECDSA) - return &inMemObscuroClient{ - obscuroAPI: clientapi.NewObscuroAPI(hostContainer.Host()), + return &inMemTenClient{ + tenAPI: clientapi.NewTenAPI(hostContainer.Host()), ethAPI: clientapi.NewEthereumAPI(hostContainer.Host(), logger), filterAPI: clientapi.NewFilterAPI(hostContainer.Host(), logger), tenScanAPI: clientapi.NewScanAPI(hostContainer.Host(), logger), @@ -58,7 +58,7 @@ func NewInMemObscuroClient(hostContainer *container.HostContainer) rpc.Client { } // Call bypasses RPC, and invokes methods on the node directly. -func (c *inMemObscuroClient) Call(result interface{}, method string, args ...interface{}) error { +func (c *inMemTenClient) Call(result interface{}, method string, args ...interface{}) error { switch method { case rpc.SendRawTransaction: return c.sendRawTransaction(result, args) @@ -118,16 +118,16 @@ func (c *inMemObscuroClient) Call(result interface{}, method string, args ...int } } -// CallContext not currently supported by in-memory obscuro client, the context will be ignored. -func (c *inMemObscuroClient) CallContext(_ context.Context, result interface{}, method string, args ...interface{}) error { +// CallContext not currently supported by in-memory ten client, the context will be ignored. +func (c *inMemTenClient) CallContext(_ context.Context, result interface{}, method string, args ...interface{}) error { return c.Call(result, method, args...) //nolint: contextcheck } -func (c *inMemObscuroClient) Subscribe(context.Context, string, interface{}, ...interface{}) (*gethrpc.ClientSubscription, error) { +func (c *inMemTenClient) Subscribe(context.Context, string, interface{}, ...interface{}) (*gethrpc.ClientSubscription, error) { panic("not implemented") } -func (c *inMemObscuroClient) sendRawTransaction(result interface{}, args []interface{}) error { +func (c *inMemTenClient) sendRawTransaction(result interface{}, args []interface{}) error { encBytes, err := getEncryptedBytes(args, rpc.SendRawTransaction) if err != nil { return err @@ -141,7 +141,7 @@ func (c *inMemObscuroClient) sendRawTransaction(result interface{}, args []inter return err } -func (c *inMemObscuroClient) getTransactionByHash(result interface{}, args []interface{}) error { +func (c *inMemTenClient) getTransactionByHash(result interface{}, args []interface{}) error { enc, err := getEncryptedBytes(args, rpc.GetTransactionByHash) if err != nil { return err @@ -156,7 +156,7 @@ func (c *inMemObscuroClient) getTransactionByHash(result interface{}, args []int return nil } -func (c *inMemObscuroClient) rpcCall(result interface{}, args []interface{}) error { +func (c *inMemTenClient) rpcCall(result interface{}, args []interface{}) error { enc, err := getEncryptedBytes(args, rpc.Call) if err != nil { return err @@ -169,7 +169,7 @@ func (c *inMemObscuroClient) rpcCall(result interface{}, args []interface{}) err return nil } -func (c *inMemObscuroClient) getTransactionReceipt(result interface{}, args []interface{}) error { +func (c *inMemTenClient) getTransactionReceipt(result interface{}, args []interface{}) error { enc, err := getEncryptedBytes(args, rpc.GetTransactionReceipt) if err != nil { return err @@ -184,7 +184,7 @@ func (c *inMemObscuroClient) getTransactionReceipt(result interface{}, args []in return nil } -func (c *inMemObscuroClient) getTransactionCount(result interface{}, args []interface{}) error { +func (c *inMemTenClient) getTransactionCount(result interface{}, args []interface{}) error { enc, err := getEncryptedBytes(args, rpc.GetTransactionCount) if err != nil { return err @@ -198,7 +198,7 @@ func (c *inMemObscuroClient) getTransactionCount(result interface{}, args []inte return nil } -func (c *inMemObscuroClient) getLogs(result interface{}, args []interface{}) error { +func (c *inMemTenClient) getLogs(result interface{}, args []interface{}) error { enc, err := getEncryptedBytes(args, rpc.GetLogs) if err != nil { return err @@ -211,7 +211,7 @@ func (c *inMemObscuroClient) getLogs(result interface{}, args []interface{}) err return nil } -func (c *inMemObscuroClient) getBatchByNumber(result interface{}, args []interface{}) error { +func (c *inMemTenClient) getBatchByNumber(result interface{}, args []interface{}) error { blockNumberHex, ok := args[0].(string) if !ok { return fmt.Errorf("arg to %s is of type %T, expected int64", rpc.GetBatchByNumber, args[0]) @@ -241,7 +241,7 @@ func (c *inMemObscuroClient) getBatchByNumber(result interface{}, args []interfa return nil } -func (c *inMemObscuroClient) getBatchByHash(result interface{}, args []interface{}) error { +func (c *inMemTenClient) getBatchByHash(result interface{}, args []interface{}) error { blockHash, ok := args[0].(gethcommon.Hash) if !ok { return fmt.Errorf("arg to %s is of type %T, expected common.Hash", rpc.GetBatchByHash, args[0]) @@ -266,24 +266,24 @@ func (c *inMemObscuroClient) getBatchByHash(result interface{}, args []interface return nil } -func (c *inMemObscuroClient) Stop() { +func (c *inMemTenClient) Stop() { // There is no RPC connection to close. } -func (c *inMemObscuroClient) SetViewingKey(_ *ecies.PrivateKey, _ []byte) { - panic("viewing key encryption/decryption is not currently supported by in-memory obscuro-client") +func (c *inMemTenClient) SetViewingKey(_ *ecies.PrivateKey, _ []byte) { + panic("viewing key encryption/decryption is not currently supported by in-memory ten-client") } -func (c *inMemObscuroClient) RegisterViewingKey(_ gethcommon.Address, _ []byte) error { - panic("viewing key encryption/decryption is not currently supported by in-memory obscuro-client") +func (c *inMemTenClient) RegisterViewingKey(_ gethcommon.Address, _ []byte) error { + panic("viewing key encryption/decryption is not currently supported by in-memory ten-client") } -func (c *inMemObscuroClient) health(result interface{}) error { +func (c *inMemTenClient) health(result interface{}) error { *result.(**hostcommon.HealthCheck) = &hostcommon.HealthCheck{OverallHealth: true} return nil } -func (c *inMemObscuroClient) getTotalTransactions(result interface{}) error { +func (c *inMemTenClient) getTotalTransactions(result interface{}) error { totalTxs, err := c.tenScanAPI.GetTotalTransactionCount() if err != nil { return fmt.Errorf("`%s` call failed. Cause: %w", rpc.GetTotalTxCount, err) @@ -293,7 +293,7 @@ func (c *inMemObscuroClient) getTotalTransactions(result interface{}) error { return nil } -func (c *inMemObscuroClient) getBatchByTx(result interface{}, args []interface{}) error { +func (c *inMemTenClient) getBatchByTx(result interface{}, args []interface{}) error { if len(args) != 1 { return fmt.Errorf("expected 1 arg to %s, got %d", rpc.GetBatchByTx, len(args)) } @@ -311,7 +311,7 @@ func (c *inMemObscuroClient) getBatchByTx(result interface{}, args []interface{} return nil } -func (c *inMemObscuroClient) getBatch(result interface{}, args []interface{}) error { +func (c *inMemTenClient) getBatch(result interface{}, args []interface{}) error { if len(args) != 1 { return fmt.Errorf("expected 1 arg to %s, got %d", rpc.GetBatch, len(args)) } @@ -329,7 +329,7 @@ func (c *inMemObscuroClient) getBatch(result interface{}, args []interface{}) er return nil } -func (c *inMemObscuroClient) getBatchListingDeprecated(result interface{}, args []interface{}) error { +func (c *inMemTenClient) getBatchListingDeprecated(result interface{}, args []interface{}) error { if len(args) != 1 { return fmt.Errorf("expected 1 arg to %s, got %d", rpc.GetBatchListing, len(args)) } @@ -351,7 +351,7 @@ func (c *inMemObscuroClient) getBatchListingDeprecated(result interface{}, args return nil } -func (c *inMemObscuroClient) getRollupListing(result interface{}, args []interface{}) error { +func (c *inMemTenClient) getRollupListing(result interface{}, args []interface{}) error { if len(args) != 1 { return fmt.Errorf("expected 1 arg to %s, got %d", rpc.GetRollupListing, len(args)) } @@ -373,7 +373,7 @@ func (c *inMemObscuroClient) getRollupListing(result interface{}, args []interfa return nil } -func (c *inMemObscuroClient) getGasPrice(result interface{}) error { +func (c *inMemTenClient) getGasPrice(result interface{}) error { gasPrice, err := c.ethAPI.GasPrice(context.Background()) if err != nil { return fmt.Errorf("`%s` call failed. Cause: %w", rpc.GasPrice, err) @@ -383,7 +383,7 @@ func (c *inMemObscuroClient) getGasPrice(result interface{}) error { return nil } -func (c *inMemObscuroClient) getPublicTransactionData(result interface{}, args []interface{}) error { +func (c *inMemTenClient) getPublicTransactionData(result interface{}, args []interface{}) error { if len(args) != 1 { return fmt.Errorf("expected 1 arg to %s, got %d", rpc.GetPublicTransactionData, len(args)) } diff --git a/integration/simulation/simulation.go b/integration/simulation/simulation.go index 5e0fe8a8ba..6bacf215c5 100644 --- a/integration/simulation/simulation.go +++ b/integration/simulation/simulation.go @@ -51,20 +51,20 @@ func (s *Simulation) Start() { testlog.Logger().Info(fmt.Sprintf("Genesis block: b_%d.", common.ShortHash(ethereummock.MockGenesisBlock.Hash()))) s.ctx = context.Background() // use injected context for graceful shutdowns - s.waitForObscuroGenesisOnL1() + s.waitForTenGenesisOnL1() // Arbitrary sleep to wait for RPC clients to get up and running // and for all l2 nodes to receive the genesis l2 batch // todo - instead of sleeping, it would be better to poll time.Sleep(10 * time.Second) - s.bridgeFundingToObscuro() - s.trackLogs() // Create log subscriptions, to validate that they're working correctly later. - s.prefundObscuroAccounts() // Prefund every L2 wallet + s.bridgeFundingToTen() + s.trackLogs() // Create log subscriptions, to validate that they're working correctly later. + s.prefundTenAccounts() // Prefund every L2 wallet - s.deployObscuroERC20s() // Deploy the Obscuro HOC and POC ERC20 contracts - s.prefundL1Accounts() // Prefund every L1 wallet - s.checkHealthStatus() // Checks the nodes health status + s.deployTenERC20s() // Deploy the Ten HOC and POC ERC20 contracts + s.prefundL1Accounts() // Prefund every L1 wallet + s.checkHealthStatus() // Checks the nodes health status timer := time.Now() fmt.Printf("Starting injection\n") @@ -91,7 +91,7 @@ func (s *Simulation) Stop() { // nothing to do for now } -func (s *Simulation) waitForObscuroGenesisOnL1() { +func (s *Simulation) waitForTenGenesisOnL1() { // grab an L1 client client := s.RPCHandles.EthClients[0] @@ -109,18 +109,18 @@ func (s *Simulation) waitForObscuroGenesisOnL1() { continue } if _, ok := t.(*ethadapter.L1RollupTx); ok { - // exit at the first obscuro rollup we see + // exit at the first Ten rollup we see return } } } } time.Sleep(s.Params.AvgBlockDuration) - testlog.Logger().Trace("Waiting for the Obscuro genesis rollup...") + testlog.Logger().Trace("Waiting for the Ten genesis rollup...") } } -func (s *Simulation) bridgeFundingToObscuro() { +func (s *Simulation) bridgeFundingToTen() { if s.Params.IsInMem { return } @@ -205,9 +205,9 @@ func (s *Simulation) trackLogs() { } // Prefunds the L2 wallets with `allocObsWallets` each. -func (s *Simulation) prefundObscuroAccounts() { +func (s *Simulation) prefundTenAccounts() { faucetWallet := s.Params.Wallets.L2FaucetWallet - faucetClient := s.RPCHandles.ObscuroWalletClient(faucetWallet.Address(), 0) // get sequencer, else errors on submission get swallowed + faucetClient := s.RPCHandles.TenWalletClient(faucetWallet.Address(), 0) // get sequencer, else errors on submission get swallowed nonce := NextNonce(s.ctx, s.RPCHandles, faucetWallet) // Give 1000 ether per account - ether is 1e18 so best convert it by code @@ -217,8 +217,8 @@ func (s *Simulation) prefundObscuroAccounts() { testcommon.PrefundWallets(s.ctx, faucetWallet, faucetClient, nonce, s.Params.Wallets.AllObsWallets(), allocObsWallets, s.Params.ReceiptTimeout) } -// This deploys an ERC20 contract on Obscuro, which is used for token arithmetic. -func (s *Simulation) deployObscuroERC20s() { +// This deploys an ERC20 contract on Ten, which is used for token arithmetic. +func (s *Simulation) deployTenERC20s() { tokens := []testcommon.ERC20{testcommon.HOC, testcommon.POC} wg := sync.WaitGroup{} @@ -239,13 +239,13 @@ func (s *Simulation) deployObscuroERC20s() { GasTipCap: gethcommon.Big1, } - deployContractTx := s.RPCHandles.ObscuroWalletRndClient(owner).EstimateGasAndGasPrice(&deployContractTxData) + deployContractTx := s.RPCHandles.TenWalletRndClient(owner).EstimateGasAndGasPrice(&deployContractTxData) signedTx, err := owner.SignTransaction(deployContractTx) if err != nil { panic(err) } - rpc := s.RPCHandles.ObscuroWalletClient(owner.Address(), 1) + rpc := s.RPCHandles.TenWalletClient(owner.Address(), 1) err = rpc.SendTransaction(s.ctx, signedTx) if err != nil { panic(err) @@ -295,7 +295,7 @@ func (s *Simulation) prefundL1Accounts() { } func (s *Simulation) checkHealthStatus() { - for _, client := range s.RPCHandles.ObscuroClients { + for _, client := range s.RPCHandles.TenClients { err := retry.Do(func() error { healthy, err := client.Health() if !healthy || err != nil { @@ -314,7 +314,7 @@ func NextNonce(ctx context.Context, clients *network.RPCHandles, w wallet.Wallet // only returns the nonce when the previous transaction was recorded for { - remoteNonce, err := clients.ObscuroWalletRndClient(w).NonceAt(ctx, nil) + remoteNonce, err := clients.TenWalletRndClient(w).NonceAt(ctx, nil) if err != nil { panic(err) } diff --git a/integration/simulation/simulation_full_network_test.go b/integration/simulation/simulation_full_network_test.go index 926f736cd8..903691d827 100644 --- a/integration/simulation/simulation_full_network_test.go +++ b/integration/simulation/simulation_full_network_test.go @@ -13,7 +13,7 @@ import ( // This test creates a network of L2 nodes, then injects transactions, and finally checks the resulting output blockchain. // The L2 nodes communicate with each other via sockets, and with their enclave servers via RPC. -// All nodes and enclaves live in the same process. The L1 network is a private geth network using Clique (PoA). +// All nodes and enclaves live in the same process. The L1 network is a private PoS geth network. func TestFullNetworkMonteCarloSimulation(t *testing.T) { setupSimTestLog("full-network") @@ -25,7 +25,7 @@ func TestFullNetworkMonteCarloSimulation(t *testing.T) { simParams := ¶ms.SimParams{ NumberOfNodes: numberOfNodes, AvgBlockDuration: 1 * time.Second, - SimulationTime: 75 * time.Second, + SimulationTime: 120 * time.Second, L1EfficiencyThreshold: 0.2, Wallets: wallets, StartPort: integration.StartPortSimulationFullNetwork, diff --git a/integration/simulation/transaction_injector.go b/integration/simulation/transaction_injector.go index 0b1a3ce907..aedbbc27d7 100644 --- a/integration/simulation/transaction_injector.go +++ b/integration/simulation/transaction_injector.go @@ -176,7 +176,7 @@ func (ti *TransactionInjector) issueRandomValueTransfers() { for txCounter := 0; ti.shouldKeepIssuing(txCounter); txCounter++ { fromWallet := ti.rndObsWallet() toWallet := ti.rndObsWallet() - obscuroClient := ti.rpcHandles.ObscuroWalletRndClient(fromWallet) + tenClient := ti.rpcHandles.TenWalletRndClient(fromWallet) // We avoid transfers to self, unless there is only a single L2 wallet. for len(ti.wallets.SimObsWallets) > 1 && fromWallet.Address().Hex() == toWallet.Address().Hex() { toWallet = ti.rndObsWallet() @@ -190,7 +190,7 @@ func (ti *TransactionInjector) issueRandomValueTransfers() { To: &toWalletAddr, } - tx := obscuroClient.EstimateGasAndGasPrice(txData) + tx := tenClient.EstimateGasAndGasPrice(txData) signedTx, err := fromWallet.SignTransaction(tx) if err != nil { panic(err) @@ -199,7 +199,7 @@ func (ti *TransactionInjector) issueRandomValueTransfers() { ti.stats.NativeTransfer() - err = obscuroClient.SendTransaction(ti.ctx, signedTx) + err = tenClient.SendTransaction(ti.ctx, signedTx) if err != nil { ti.logger.Info("Failed to issue transfer via RPC.", log.ErrKey, err) continue @@ -217,13 +217,13 @@ func (ti *TransactionInjector) issueRandomTransfers() { for txCounter := 0; ti.shouldKeepIssuing(txCounter); txCounter++ { fromWallet := ti.rndObsWallet() toWallet := ti.rndObsWallet() - obscuroClient := ti.rpcHandles.ObscuroWalletRndClient(fromWallet) + tenClient := ti.rpcHandles.TenWalletRndClient(fromWallet) // We avoid transfers to self, unless there is only a single L2 wallet. for len(ti.wallets.SimObsWallets) > 1 && fromWallet.Address().Hex() == toWallet.Address().Hex() { toWallet = ti.rndObsWallet() } - tx := ti.newObscuroTransferTx(fromWallet, toWallet.Address(), testcommon.RndBtw(1, 500), testcommon.HOC) - tx = obscuroClient.EstimateGasAndGasPrice(tx) + tx := ti.newTenTransferTx(fromWallet, toWallet.Address(), testcommon.RndBtw(1, 500), testcommon.HOC) + tx = tenClient.EstimateGasAndGasPrice(tx) signedTx, err := fromWallet.SignTransaction(tx) if err != nil { panic(err) @@ -232,7 +232,7 @@ func (ti *TransactionInjector) issueRandomTransfers() { ti.stats.Transfer() - err = obscuroClient.SendTransaction(ti.ctx, signedTx) + err = tenClient.SendTransaction(ti.ctx, signedTx) if err != nil { ti.logger.Info("Failed to issue transfer via RPC.", log.ErrKey, err) } @@ -297,10 +297,10 @@ func (ti *TransactionInjector) issueRandomDeposits() { } fromWallet := ti.wallets.Tokens[fromWalletToken].L2Owner toWallet := ti.rndObsWallet() - obscuroClient := ti.rpcHandles.ObscuroWalletRndClient(fromWallet) + tenClient := ti.rpcHandles.TenWalletRndClient(fromWallet) v := testcommon.RndBtw(500, 2000) - txData := ti.newObscuroTransferTx(fromWallet, toWallet.Address(), v, fromWalletToken) - tx := obscuroClient.EstimateGasAndGasPrice(txData) + txData := ti.newTenTransferTx(fromWallet, toWallet.Address(), v, fromWalletToken) + tx := tenClient.EstimateGasAndGasPrice(txData) signedTx, err := fromWallet.SignTransaction(tx) if err != nil { panic(err) @@ -309,7 +309,7 @@ func (ti *TransactionInjector) issueRandomDeposits() { ti.stats.Deposit(big.NewInt(int64(v))) - err = obscuroClient.SendTransaction(ti.ctx, signedTx) + err = tenClient.SendTransaction(ti.ctx, signedTx) if err != nil { ti.logger.Info("Failed to issue deposit via RPC.", log.ErrKey, err) } else { @@ -327,18 +327,18 @@ func (ti *TransactionInjector) awaitAndFinalizeWithdrawal(tx *types.Transaction, return } - err := testcommon.AwaitReceipt(ti.ctx, ti.rpcHandles.ObscuroWalletRndClient(fromWallet), tx.Hash(), 30*time.Second) + err := testcommon.AwaitReceipt(ti.ctx, ti.rpcHandles.TenWalletRndClient(fromWallet), tx.Hash(), 45*time.Second) if err != nil { ti.logger.Error("Failed to await receipt for withdrawal transaction", log.ErrKey, err) return } - receipt, err := ti.rpcHandles.ObscuroWalletRndClient(fromWallet).TransactionReceipt(ti.ctx, tx.Hash()) + receipt, err := ti.rpcHandles.TenWalletRndClient(fromWallet).TransactionReceipt(ti.ctx, tx.Hash()) if err != nil { ti.logger.Error("Failed to retrieve receipt for withdrawal transaction", log.ErrKey, err) return } - header, err := ti.rpcHandles.ObscuroWalletRndClient(fromWallet).GetBatchHeaderByHash(receipt.BlockHash) + header, err := ti.rpcHandles.TenWalletRndClient(fromWallet).GetBatchHeaderByHash(receipt.BlockHash) if err != nil { ti.logger.Error("Failed to retrieve batch header for withdrawal transaction", log.ErrKey, err) return @@ -451,7 +451,7 @@ func (ti *TransactionInjector) issueRandomWithdrawals() { for txCounter := 0; ti.shouldKeepIssuing(txCounter); txCounter++ { fromWallet := ti.rndObsWallet() - client := ti.rpcHandles.ObscuroWalletRndClient(fromWallet) + client := ti.rpcHandles.TenWalletRndClient(fromWallet) price, err := client.GasPrice(ti.ctx) if err != nil { ti.logger.Error("unable to estimate gas price", log.ErrKey, err) @@ -498,12 +498,12 @@ func (ti *TransactionInjector) issueInvalidL2Txs() { for len(ti.wallets.SimObsWallets) > 1 && fromWallet.Address().Hex() == toWallet.Address().Hex() { toWallet = ti.rndObsWallet() } - txData := ti.newCustomObscuroWithdrawalTx(testcommon.RndBtw(1, 100)) + txData := ti.newCustomTenWithdrawalTx(testcommon.RndBtw(1, 100)) - tx := ti.rpcHandles.ObscuroWalletRndClient(fromWallet).EstimateGasAndGasPrice(txData) + tx := ti.rpcHandles.TenWalletRndClient(fromWallet).EstimateGasAndGasPrice(txData) signedTx := ti.createInvalidSignage(tx, fromWallet) - err := ti.rpcHandles.ObscuroWalletRndClient(fromWallet).SendTransaction(ti.ctx, signedTx) + err := ti.rpcHandles.TenWalletRndClient(fromWallet).SendTransaction(ti.ctx, signedTx) if err != nil { ti.logger.Info("Failed to issue withdrawal via RPC. ", log.ErrKey, err) } @@ -530,12 +530,12 @@ func (ti *TransactionInjector) rndObsWallet() wallet.Wallet { return ti.wallets.SimObsWallets[rand.Intn(len(ti.wallets.SimObsWallets))] //nolint:gosec } -func (ti *TransactionInjector) newObscuroTransferTx(from wallet.Wallet, dest gethcommon.Address, amount uint64, ercType testcommon.ERC20) types.TxData { +func (ti *TransactionInjector) newTenTransferTx(from wallet.Wallet, dest gethcommon.Address, amount uint64, ercType testcommon.ERC20) types.TxData { data := erc20contractlib.CreateTransferTxData(dest, common.ValueInWei(big.NewInt(int64(amount)))) return ti.newTx(data, from.GetNonceAndIncrement(), ercType) } -func (ti *TransactionInjector) newCustomObscuroWithdrawalTx(amount uint64) types.TxData { +func (ti *TransactionInjector) newCustomTenWithdrawalTx(amount uint64) types.TxData { transferERC20data := erc20contractlib.CreateTransferTxData(testcommon.BridgeAddress, common.ValueInWei(big.NewInt(int64(amount)))) return ti.newTx(transferERC20data, 1, testcommon.HOC) } diff --git a/integration/simulation/validate_chain.go b/integration/simulation/validate_chain.go index 91d417472b..a4ebc91c5f 100644 --- a/integration/simulation/validate_chain.go +++ b/integration/simulation/validate_chain.go @@ -41,7 +41,7 @@ const ( // more than this, but this is a sanity check to ensure the simulation doesn't stop after a single transaction of each // type, for example. txThreshold = 5 - // The maximum number of blocks an Obscuro node can fall behind + // The maximum number of blocks an Ten node can fall behind maxBlockDelay = 5 // The leading zero bytes in a hash indicating that it is possibly an address, since it only has 20 bytes of data. zeroBytesHex = "000000000000000000000000" @@ -49,12 +49,12 @@ const ( // After a simulation has run, check as much as possible that the outputs of the simulation are expected. // For example, all injected transactions were processed correctly, the height of the rollup chain is a function of the total -// time of the simulation and the average block duration, that all Obscuro nodes are roughly in sync, etc +// time of the simulation and the average block duration, that all Ten nodes are roughly in sync, etc func checkNetworkValidity(t *testing.T, s *Simulation) { time.Sleep(2 * time.Second) checkTransactionsInjected(t, s) l1MaxHeight := checkEthereumBlockchainValidity(t, s) - checkObscuroBlockchainValidity(t, s, l1MaxHeight) + checkTenBlockchainValidity(t, s, l1MaxHeight) checkReceivedLogs(t, s) checkTenscan(t, s) } @@ -100,30 +100,30 @@ func checkEthereumBlockchainValidity(t *testing.T, s *Simulation) uint64 { return max } -// checkObscuroBlockchainValidity - perform the following checks +// checkTenBlockchainValidity - perform the following checks // - minimum height - the chain has a minimum number of rollups // - check height is similar // - check no duplicate txs // - check efficiency - no of created blocks/ height // - check amount in the system // - check withdrawals/deposits -func checkObscuroBlockchainValidity(t *testing.T, s *Simulation, maxL1Height uint64) { +func checkTenBlockchainValidity(t *testing.T, s *Simulation, maxL1Height uint64) { // Sanity check number for a minimum height minHeight := uint64(float64(s.Params.SimulationTime.Microseconds()) / (2 * float64(s.Params.AvgBlockDuration))) // process the blockchain of each node in parallel to minimize the difference between them since they are still running - heights := make([]uint64, len(s.RPCHandles.ObscuroClients)) + heights := make([]uint64, len(s.RPCHandles.TenClients)) var wg sync.WaitGroup - for idx := range s.RPCHandles.ObscuroClients { + for idx := range s.RPCHandles.TenClients { wg.Add(1) - go checkBlockchainOfObscuroNode(t, s.RPCHandles, minHeight, maxL1Height, s, &wg, heights, idx) + go checkBlockchainOfTenNode(t, s.RPCHandles, minHeight, maxL1Height, s, &wg, heights, idx) } wg.Wait() min, max := minMax(heights) // This checks that all the nodes are in sync. When a node falls behind with processing blocks it might highlight a problem. // since there is one node that only listens to rollups it will be naturally behind. if max-min > max/3 { - t.Errorf("There is a problem with the Obscuro chain. Nodes fell out of sync. Max height: %d. Min height: %d -> %+v", max, min, heights) + t.Errorf("There is a problem with the Ten chain. Nodes fell out of sync. Max height: %d. Min height: %d -> %+v", max, min, heights) } } @@ -294,7 +294,8 @@ func ExtractDataFromEthereumChain( } func verifyGasBridgeTransactions(t *testing.T, s *Simulation, nodeIdx int) { - time.Sleep(3 * time.Second) + // takes longer for the funds to be bridged across + time.Sleep(45 * time.Second) mbusABI, _ := abi.JSON(strings.NewReader(MessageBus.MessageBusMetaData.ABI)) gasBridgeRecords := s.TxInjector.TxTracker.GasBridgeTransactions for _, record := range gasBridgeRecords { @@ -321,9 +322,9 @@ func verifyGasBridgeTransactions(t *testing.T, s *Simulation, nodeIdx int) { } } -func checkBlockchainOfObscuroNode(t *testing.T, rpcHandles *network.RPCHandles, minObscuroHeight uint64, maxEthereumHeight uint64, s *Simulation, wg *sync.WaitGroup, heights []uint64, nodeIdx int) { +func checkBlockchainOfTenNode(t *testing.T, rpcHandles *network.RPCHandles, minTenHeight uint64, maxEthereumHeight uint64, s *Simulation, wg *sync.WaitGroup, heights []uint64, nodeIdx int) { defer wg.Done() - obscuroClient := rpcHandles.ObscuroClients[nodeIdx] + tenClient := rpcHandles.TenClients[nodeIdx] // check that the L1 view is consistent with the L1 network. // We cast to int64 to avoid an overflow when l1Height is greater than maxEthereumHeight (due to additional blocks @@ -334,11 +335,11 @@ func checkBlockchainOfObscuroNode(t *testing.T, rpcHandles *network.RPCHandles, t.Errorf("Node %d: Could not retrieve L1 height. Cause: %s", nodeIdx, err) } if int(maxEthereumHeight)-int(l1Height) > maxBlockDelay { - t.Errorf("Node %d: Obscuro node fell behind by %d blocks.", nodeIdx, maxEthereumHeight-l1Height) + t.Errorf("Node %d: Ten node fell behind by %d blocks.", nodeIdx, maxEthereumHeight-l1Height) } // check that the height of the l2 chain is higher than a minimum expected value. - headBatchHeader, err := getHeadBatchHeader(obscuroClient) + headBatchHeader, err := getHeadBatchHeader(tenClient) if err != nil { t.Error(fmt.Errorf("node %d: %w", nodeIdx, err)) } @@ -348,12 +349,12 @@ func checkBlockchainOfObscuroNode(t *testing.T, rpcHandles *network.RPCHandles, return } l2Height := headBatchHeader.Number - if l2Height.Uint64() < minObscuroHeight { - t.Errorf("Node %d: Node only mined %d rollups. Expected at least: %d.", nodeIdx, l2Height, minObscuroHeight) + if l2Height.Uint64() < minTenHeight { + t.Errorf("Node %d: Node only mined %d rollups. Expected at least: %d.", nodeIdx, l2Height, minTenHeight) } // check that the height from the head batch header is consistent with the height returned by eth_blockNumber. - l2HeightFromBatchNumber, err := obscuroClient.BatchNumber() + l2HeightFromBatchNumber, err := tenClient.BatchNumber() if err != nil { t.Errorf("Node %d: Could not retrieve block number. Cause: %s", nodeIdx, err) } @@ -382,9 +383,9 @@ func checkBlockchainOfObscuroNode(t *testing.T, rpcHandles *network.RPCHandles, checkTransactionReceipts(s.ctx, t, nodeIdx, rpcHandles, s.TxInjector) - totalSuccessfullyWithdrawn := extractWithdrawals(t, obscuroClient, nodeIdx) + totalSuccessfullyWithdrawn := extractWithdrawals(t, tenClient, nodeIdx) - totalAmountLogged := getLoggedWithdrawals(minObscuroHeight, obscuroClient, headBatchHeader) + totalAmountLogged := getLoggedWithdrawals(minTenHeight, tenClient, headBatchHeader) if totalAmountLogged.Cmp(totalSuccessfullyWithdrawn) != 0 { t.Errorf("Node %d: Logged withdrawals do not match!", nodeIdx) } @@ -412,7 +413,7 @@ func checkBlockchainOfObscuroNode(t *testing.T, rpcHandles *network.RPCHandles, // totalAmountInSystem := big.NewInt(0).Sub(s.Stats.TotalDepositedAmount, totalSuccessfullyWithdrawn) total := big.NewInt(0) for _, wallet := range s.Params.Wallets.SimObsWallets { - client := rpcHandles.ObscuroWalletClient(wallet.Address(), nodeIdx) + client := rpcHandles.TenWalletClient(wallet.Address(), nodeIdx) bal := balance(s.ctx, client, wallet.Address(), s.Params.Wallets.Tokens[testcommon.HOC].L2ContractAddress, nodeIdx) total.Add(total, bal) } @@ -430,7 +431,7 @@ func checkBlockchainOfObscuroNode(t *testing.T, rpcHandles *network.RPCHandles, return } // check that the headers are serialised and deserialised correctly, by recomputing a header's hash - parentHeader, err := obscuroClient.GetBatchHeaderByHash(headBatchHeader.ParentHash) + parentHeader, err := tenClient.GetBatchHeaderByHash(headBatchHeader.ParentHash) if err != nil { t.Errorf("could not retrieve parent of head batch") return @@ -440,10 +441,10 @@ func checkBlockchainOfObscuroNode(t *testing.T, rpcHandles *network.RPCHandles, } } -func getLoggedWithdrawals(minObscuroHeight uint64, obscuroClient *obsclient.ObsClient, currentHeader *common.BatchHeader) *big.Int { +func getLoggedWithdrawals(minTenHeight uint64, tenClient *obsclient.ObsClient, currentHeader *common.BatchHeader) *big.Int { totalAmountLogged := big.NewInt(0) - for i := minObscuroHeight; i < currentHeader.Number.Uint64(); i++ { - header, err := obscuroClient.GetBatchHeaderByNumber(big.NewInt(int64(i))) + for i := minTenHeight; i < currentHeader.Number.Uint64(); i++ { + header, err := tenClient.GetBatchHeaderByNumber(big.NewInt(int64(i))) if err != nil { panic(err) } @@ -475,7 +476,7 @@ func FindNotIncludedL2Txs(ctx context.Context, nodeIdx int, rpcHandles *network. for _, tx := range transfers { sender := getSender(tx) // because of viewing key encryption we need to get the RPC client for this specific node for the wallet that sent the transaction - l2tx, _, err := rpcHandles.ObscuroWalletClient(sender, nodeIdx).TransactionByHash(ctx, tx.Hash()) + l2tx, _, err := rpcHandles.TenWalletClient(sender, nodeIdx).TransactionByHash(ctx, tx.Hash()) if err != nil || l2tx == nil { notFoundTransfers++ } @@ -485,7 +486,7 @@ func FindNotIncludedL2Txs(ctx context.Context, nodeIdx int, rpcHandles *network. for _, tx := range withdrawals { sender := getSender(tx) // because of viewing key encryption we need to get the RPC client for this specific node for the wallet that sent the transaction - l2tx, _, err := rpcHandles.ObscuroWalletClient(sender, nodeIdx).TransactionByHash(ctx, tx.Hash()) + l2tx, _, err := rpcHandles.TenWalletClient(sender, nodeIdx).TransactionByHash(ctx, tx.Hash()) if err != nil || l2tx == nil { notFoundWithdrawals++ } @@ -495,7 +496,7 @@ func FindNotIncludedL2Txs(ctx context.Context, nodeIdx int, rpcHandles *network. for _, tx := range nativeTransfers { sender := getSender(tx) // because of viewing key encryption we need to get the RPC client for this specific node for the wallet that sent the transaction - l2tx, _, err := rpcHandles.ObscuroWalletClient(sender, nodeIdx).TransactionByHash(ctx, tx.Hash()) + l2tx, _, err := rpcHandles.TenWalletClient(sender, nodeIdx).TransactionByHash(ctx, tx.Hash()) if err != nil || l2tx == nil { notFoundNativeTransfers++ } @@ -521,7 +522,7 @@ func checkTransactionReceipts(ctx context.Context, t *testing.T, nodeIdx int, rp sender := getSender(tx) // We check that there is a receipt available for each transaction - receipt, err := rpcHandles.ObscuroWalletClient(sender, nodeIdx).TransactionReceipt(ctx, tx.Hash()) + receipt, err := rpcHandles.TenWalletClient(sender, nodeIdx).TransactionReceipt(ctx, tx.Hash()) if err != nil { t.Errorf("node %d: could not retrieve receipt for transaction %s. Cause: %s", nodeIdx, tx.Hash().Hex(), err) continue @@ -547,7 +548,7 @@ func checkTransactionReceipts(ctx context.Context, t *testing.T, nodeIdx int, rp for _, tx := range txInjector.TxTracker.WithdrawalL2Transactions { sender := getSender(tx) - receipt, err := rpcHandles.ObscuroWalletClient(sender, nodeIdx).TransactionReceipt(ctx, tx.Hash()) + receipt, err := rpcHandles.TenWalletClient(sender, nodeIdx).TransactionReceipt(ctx, tx.Hash()) if err != nil { continue } @@ -577,9 +578,9 @@ func checkTransactionReceipts(ctx context.Context, t *testing.T, nodeIdx int, rp } } -func extractWithdrawals(t *testing.T, obscuroClient *obsclient.ObsClient, nodeIdx int) (totalSuccessfullyWithdrawn *big.Int) { +func extractWithdrawals(t *testing.T, tenClient *obsclient.ObsClient, nodeIdx int) (totalSuccessfullyWithdrawn *big.Int) { totalSuccessfullyWithdrawn = big.NewInt(0) - header, err := getHeadBatchHeader(obscuroClient) + header, err := getHeadBatchHeader(tenClient) if err != nil { t.Error(fmt.Errorf("node %d: %w", nodeIdx, err)) } @@ -598,7 +599,7 @@ func extractWithdrawals(t *testing.T, obscuroClient *obsclient.ObsClient, nodeId } // note this retrieves batches currently. - newHeader, err := obscuroClient.GetBatchHeaderByHash(header.ParentHash) + newHeader, err := tenClient.GetBatchHeaderByHash(header.ParentHash) if err != nil { t.Errorf(fmt.Sprintf("Node %d: Could not retrieve batch header %s. Cause: %s", nodeIdx, header.ParentHash, err)) return diff --git a/integration/smartcontract/debug_wallet.go b/integration/smartcontract/debug_wallet.go index b8b0dc297f..41475c22ac 100644 --- a/integration/smartcontract/debug_wallet.go +++ b/integration/smartcontract/debug_wallet.go @@ -12,7 +12,7 @@ import ( "github.com/ten-protocol/go-ten/go/wallet" ) -var _timeout = 30 * time.Second +var _timeout = 60 * time.Second // debugWallet is a wrapper around the wallet that simplifies commonly used functions type debugWallet struct { diff --git a/integration/smartcontract/smartcontracts_test.go b/integration/smartcontract/smartcontracts_test.go index 4426836f20..062e063607 100644 --- a/integration/smartcontract/smartcontracts_test.go +++ b/integration/smartcontract/smartcontracts_test.go @@ -30,7 +30,7 @@ const _startPort = integration.StartPortSmartContractTests type netInfo struct { ethClients []ethadapter.EthClient wallets []wallet.Wallet - eth2Network eth2network.Eth2Network + eth2Network eth2network.PosEth2Network } var testLogs = "../.build/noderunner/" @@ -47,7 +47,7 @@ func init() { //nolint:gochecknoinits // runGethNetwork runs a geth network with one prefunded wallet func runGethNetwork(t *testing.T) *netInfo { // make sure the geth network binaries exist - path, err := eth2network.EnsureBinariesExist() + binDir, err := eth2network.EnsureBinariesExist() if err != nil { t.Fatal(err) } @@ -55,23 +55,17 @@ func runGethNetwork(t *testing.T) *netInfo { // prefund one wallet as the worker wallet workerWallet := datagenerator.RandomWallet(integration.EthereumChainID) - // define + run the network - eth2Network := eth2network.NewEth2Network( - path, - true, - _startPort, - _startPort+integration.DefaultGethWSPortOffset, - _startPort+integration.DefaultGethAUTHPortOffset, + eth2Network := eth2network.NewPosEth2Network( + binDir, _startPort+integration.DefaultGethNetworkPortOffset, - _startPort+integration.DefaultPrysmHTTPPortOffset, _startPort+integration.DefaultPrysmP2PPortOffset, - 1337, - 1, - 1, - 2, - 2, - []string{workerWallet.Address().String()}, - 2*time.Minute, + _startPort+integration.DefaultGethAUTHPortOffset, // RPC + _startPort+integration.DefaultGethWSPortOffset, + _startPort+integration.DefaultGethHTTPPortOffset, + _startPort+integration.DefaultPrysmRPCPortOffset, // RPC + integration.EthereumChainID, + 3*time.Minute, + workerWallet.Address().String(), ) if err = eth2Network.Start(); err != nil { @@ -79,7 +73,7 @@ func runGethNetwork(t *testing.T) *netInfo { } // create a client that is connected to node 0 of the network - client, err := ethadapter.NewEthClient("127.0.0.1", integration.StartPortSmartContractTests+100, 30*time.Second, gethcommon.HexToAddress("0x0"), testlog.Logger()) + client, err := ethadapter.NewEthClient("127.0.0.1", integration.StartPortSmartContractTests+100, 60*time.Second, gethcommon.HexToAddress("0x0"), testlog.Logger()) if err != nil { t.Fatal(err) } @@ -96,7 +90,7 @@ func TestManagementContract(t *testing.T) { sim := runGethNetwork(t) defer sim.eth2Network.Stop() //nolint: errcheck - // setup the client and the (debug) wallet + // set up the client and the (debug) wallet client := sim.ethClients[0] w := newDebugWallet(sim.wallets[0]) diff --git a/integration/obscurogateway/errors_contract.go b/integration/tengateway/errors_contract.go similarity index 99% rename from integration/obscurogateway/errors_contract.go rename to integration/tengateway/errors_contract.go index 67e2c076ad..aec58c7eed 100644 --- a/integration/obscurogateway/errors_contract.go +++ b/integration/tengateway/errors_contract.go @@ -1,4 +1,4 @@ -package obscurogateway +package tengateway import ( "strings" diff --git a/integration/obscurogateway/events_contract.go b/integration/tengateway/events_contract.go similarity index 99% rename from integration/obscurogateway/events_contract.go rename to integration/tengateway/events_contract.go index 2815f56f2b..19057ab4ee 100644 --- a/integration/obscurogateway/events_contract.go +++ b/integration/tengateway/events_contract.go @@ -1,4 +1,4 @@ -package obscurogateway +package tengateway import ( "strings" diff --git a/integration/obscurogateway/gateway_user.go b/integration/tengateway/gateway_user.go similarity index 99% rename from integration/obscurogateway/gateway_user.go rename to integration/tengateway/gateway_user.go index b37445c504..0c4f2793bd 100644 --- a/integration/obscurogateway/gateway_user.go +++ b/integration/tengateway/gateway_user.go @@ -1,4 +1,4 @@ -package obscurogateway +package tengateway import ( "context" diff --git a/integration/obscurogateway/json.go b/integration/tengateway/json.go similarity index 96% rename from integration/obscurogateway/json.go rename to integration/tengateway/json.go index 41b8629f0c..2e4bebc579 100644 --- a/integration/obscurogateway/json.go +++ b/integration/tengateway/json.go @@ -1,4 +1,4 @@ -package obscurogateway +package tengateway import ( "encoding/json" diff --git a/integration/obscurogateway/tengateway_test.go b/integration/tengateway/tengateway_test.go similarity index 98% rename from integration/obscurogateway/tengateway_test.go rename to integration/tengateway/tengateway_test.go index 43778e5d35..cfcf2a9af8 100644 --- a/integration/obscurogateway/tengateway_test.go +++ b/integration/tengateway/tengateway_test.go @@ -1,4 +1,4 @@ -package obscurogateway +package tengateway import ( "bytes" @@ -56,19 +56,19 @@ func init() { //nolint:gochecknoinits } const ( - testLogs = "../.build/tengateway/" + testLogs = "../.build/tengateway/" + _startPort = integration.StartPortTenGatewayUnitTest ) func TestTenGateway(t *testing.T) { - startPort := integration.StartPortTenGatewayUnitTest - createTenNetwork(t, startPort) + createTenNetwork(t, _startPort) tenGatewayConf := wecommon.Config{ WalletExtensionHost: "127.0.0.1", - WalletExtensionPortHTTP: startPort + integration.DefaultTenGatewayHTTPPortOffset, - WalletExtensionPortWS: startPort + integration.DefaultTenGatewayWSPortOffset, - NodeRPCHTTPAddress: fmt.Sprintf("127.0.0.1:%d", startPort+integration.DefaultHostRPCHTTPOffset), - NodeRPCWebsocketAddress: fmt.Sprintf("127.0.0.1:%d", startPort+integration.DefaultHostRPCWSOffset), + WalletExtensionPortHTTP: _startPort + integration.DefaultTenGatewayHTTPPortOffset, + WalletExtensionPortWS: _startPort + integration.DefaultTenGatewayWSPortOffset, + NodeRPCHTTPAddress: fmt.Sprintf("127.0.0.1:%d", _startPort+integration.DefaultHostRPCHTTPOffset), + NodeRPCWebsocketAddress: fmt.Sprintf("127.0.0.1:%d", _startPort+integration.DefaultHostRPCWSOffset), LogPath: "sys_out", VerboseFlag: false, DBType: "sqlite", @@ -489,7 +489,6 @@ func testErrorHandling(t *testing.T, httpURL, wsURL string, w wallet.Wallet) { require.NoError(t, err) // make requests to geth for comparison - for _, req := range []string{ `{"jsonrpc":"2.0","method":"eth_getLogs","params":[[]],"id":1}`, `{"jsonrpc":"2.0","method":"eth_getLogs","params":[{"topics":[]}],"id":1}`, @@ -511,7 +510,7 @@ func testErrorHandling(t *testing.T, httpURL, wsURL string, w wallet.Wallet) { `{"jsonrpc":"2.0","method":"eth_getTransactionByHash","params":["0x0000000000000000000000000000000000000000000000000000000000000000"],"id":1}`, `{"jsonrpc":"2.0","method":"eth_maxPriorityFeePerGas","params":[],"id":1}`, } { - // ensure the geth request is issued correctly (should return 200 ok with jsonRPCError) + // ensure the gateway request is issued correctly (should return 200 ok with jsonRPCError) _, response, err := httputil.PostDataJSON(ogClient.HTTP(), []byte(req)) require.NoError(t, err) fmt.Printf("Resp: %s", response) @@ -521,8 +520,8 @@ func testErrorHandling(t *testing.T, httpURL, wsURL string, w wallet.Wallet) { err = json.Unmarshal(response, &jsonRPCError) require.NoError(t, err, req, response) - // repeat the process for the gateway - _, response, err = httputil.PostDataJSON(fmt.Sprintf("http://localhost:%d", integration.StartPortTenGatewayUnitTest), []byte(req)) + // repeat the process for geth + _, response, err = httputil.PostDataJSON(fmt.Sprintf("http://localhost:%d", _startPort+integration.DefaultGethHTTPPortOffset), []byte(req)) require.NoError(t, err) // we only care about format diff --git a/integration/tenscan/tenscan_test.go b/integration/tenscan/tenscan_test.go index 9c0ce273c0..a76a9f1eff 100644 --- a/integration/tenscan/tenscan_test.go +++ b/integration/tenscan/tenscan_test.go @@ -49,7 +49,7 @@ const ( func TestTenscan(t *testing.T) { startPort := integration.StartPortTenscanUnitTest - createObscuroNetwork(t, startPort) + createTenNetwork(t, startPort) tenScanConfig := &config.Config{ NodeHostAddress: fmt.Sprintf("http://127.0.0.1:%d", startPort+integration.DefaultHostRPCHTTPOffset), @@ -199,8 +199,8 @@ func TestTenscan(t *testing.T) { rollupListingObj := rollupListing{} err = json.Unmarshal(body, &rollupListingObj) assert.NoError(t, err) - assert.LessOrEqual(t, 4, len(rollupListingObj.Result.RollupsData)) - assert.LessOrEqual(t, uint64(4), rollupListingObj.Result.Total) + assert.LessOrEqual(t, 1, len(rollupListingObj.Result.RollupsData)) + assert.LessOrEqual(t, uint64(1), rollupListingObj.Result.Total) assert.Contains(t, string(body), "\"hash\"") // fetch batches in rollup @@ -261,7 +261,7 @@ func TestTenscan(t *testing.T) { assert.Equal(t, 200, statusCode) type configFetch struct { - Item common.ObscuroNetworkInfo `json:"item"` + Item common.TenNetworkInfo `json:"item"` } configFetchObj := configFetch{} @@ -290,9 +290,9 @@ func waitServerIsReady(serverAddr string) error { return fmt.Errorf("timed out before server was ready") } -// Creates a single-node Obscuro network for testing. -func createObscuroNetwork(t *testing.T, startPort int) { - // Create the Obscuro network. +// Creates a single-node Ten network for testing. +func createTenNetwork(t *testing.T, startPort int) { + // Create the Ten network. wallets := params.NewSimWallets(1, 1, integration.EthereumChainID, integration.TenChainID) simParams := params.SimParams{ NumberOfNodes: 1, @@ -304,11 +304,11 @@ func createObscuroNetwork(t *testing.T, startPort int) { WithPrefunding: true, } - obscuroNetwork := network.NewNetworkOfSocketNodes(wallets) - t.Cleanup(obscuroNetwork.TearDown) - _, err := obscuroNetwork.Create(&simParams, nil) + tenNetwork := network.NewNetworkOfSocketNodes(wallets) + t.Cleanup(tenNetwork.TearDown) + _, err := tenNetwork.Create(&simParams, nil) if err != nil { - panic(fmt.Sprintf("failed to create test Obscuro network. Cause: %s", err)) + panic(fmt.Sprintf("failed to create test Ten network. Cause: %s", err)) } } @@ -359,7 +359,7 @@ func issueTransactions(t *testing.T, hostWSAddr string, issuerWallet wallet.Wall for _, txHash := range receipts { fmt.Printf("Checking for tx receipt for %s \n", txHash) var receipt *types.Receipt - for start := time.Now(); time.Since(start) < time.Minute; time.Sleep(time.Second) { + for start := time.Now(); time.Since(start) < 2*time.Minute; time.Sleep(time.Second) { receipt, err = authClient.TransactionReceipt(ctx, txHash) if err == nil { break @@ -371,7 +371,7 @@ func issueTransactions(t *testing.T, hostWSAddr string, issuerWallet wallet.Wall } if receipt == nil { - t.Fatalf("Did not mine the transaction after %s seconds - receipt: %+v", 30*time.Second, receipt) + t.Fatalf("Did not mine the transaction after %s seconds - receipt: %+v", 60*time.Second, receipt) } if receipt.Status == 0 { t.Fatalf("Tx Failed") diff --git a/testnet/eth2network.Dockerfile b/testnet/eth2network.Dockerfile index 080db4d15c..0715383f7d 100644 --- a/testnet/eth2network.Dockerfile +++ b/testnet/eth2network.Dockerfile @@ -34,5 +34,5 @@ RUN --mount=type=cache,target=/root/.cache/go-build \ # RUN ./main --onlyDownload=true # expose the http and the ws ports to the host -EXPOSE 12000 12100 12200 12300 12400 -ENTRYPOINT ["/home/obscuro/go-obscuro/integration/eth2network/main/main", "--numNodes=1"] +EXPOSE 12000 12100 12200 12300 12400 12500 +ENTRYPOINT ["/home/obscuro/go-obscuro/integration/eth2network/main/main"] diff --git a/testnet/launcher/docker.go b/testnet/launcher/docker.go index 61c9d60603..1954bfafa2 100644 --- a/testnet/launcher/docker.go +++ b/testnet/launcher/docker.go @@ -73,14 +73,14 @@ func (t *Testnet) Start() error { err = sequencerNode.Start() if err != nil { - return fmt.Errorf("unable to start the obscuro node - %w", err) + return fmt.Errorf("unable to start the Ten node - %w", err) } - fmt.Println("Obscuro node was successfully started...") + fmt.Println("Ten node was successfully started...") // wait until the node is healthy err = waitForHealthyNode(80) if err != nil { - return fmt.Errorf("sequencer obscuro node not healthy - %w", err) + return fmt.Errorf("sequencer Ten node not healthy - %w", err) } validatorNodeConfig := node.NewNodeConfig( @@ -119,7 +119,7 @@ func (t *Testnet) Start() error { if err != nil { return fmt.Errorf("unable to start the obscuro node - %w", err) } - fmt.Println("Obscuro node was successfully started...") + fmt.Println("Ten validator node was successfully started...") // wait until the node it healthy err = waitForHealthyNode(13010) diff --git a/testnet/launcher/eth2network/docker.go b/testnet/launcher/eth2network/docker.go index bed408d44a..8c681eb85e 100644 --- a/testnet/launcher/eth2network/docker.go +++ b/testnet/launcher/eth2network/docker.go @@ -27,7 +27,6 @@ func (n *Eth2Network) Start() error { cmds := []string{ "/home/obscuro/go-obscuro/integration/eth2network/main/main", - "--numNodes", "1", } if len(n.cfg.prefundedAddrs) > 1 { @@ -53,7 +52,7 @@ func (n *Eth2Network) Start() error { } func (n *Eth2Network) IsReady() error { - timeout := 20 * time.Minute // this can be reduced when we no longer download the ethereum binaries + timeout := 10 * time.Minute // this can be reduced when we no longer download the ethereum binaries interval := 2 * time.Second var dial *ethclient.Client var err error diff --git a/testnet/testnet-local-eth2network.sh b/testnet/testnet-local-eth2network.sh index 5d74c4a04b..de8fc495e7 100755 --- a/testnet/testnet-local-eth2network.sh +++ b/testnet/testnet-local-eth2network.sh @@ -61,7 +61,6 @@ docker run --name=eth2network -d \ -p 8025:8025 -p 8026:8026 -p 9000:9000 -p 9001:9001 \ --entrypoint /home/obscuro/go-obscuro/integration/eth2network/main/main \ testnetobscuronet.azurecr.io/obscuronet/eth2network:latest \ - --numNodes=1 \ --gethHTTPStartPort=${port} \ --gethWSStartPort=${wsport} \ --prefundedAddrs=${pkaddresses} diff --git a/tools/hardhatdeployer/contract_deployer.go b/tools/hardhatdeployer/contract_deployer.go index 2dec817c29..59684be16e 100644 --- a/tools/hardhatdeployer/contract_deployer.go +++ b/tools/hardhatdeployer/contract_deployer.go @@ -27,7 +27,7 @@ const ( ) const ( - timeoutWait = 80 * time.Second + timeoutWait = 120 * time.Second retryInterval = 2 * time.Second Prealloc = 2_050_000_000_000_000_000 // The amount preallocated to the contract deployer wallet. ) diff --git a/tools/tenscan/backend/obscuroscan_backend.go b/tools/tenscan/backend/obscuroscan_backend.go index e823cb2ce8..53213fe4a4 100644 --- a/tools/tenscan/backend/obscuroscan_backend.go +++ b/tools/tenscan/backend/obscuroscan_backend.go @@ -162,6 +162,6 @@ func (b *Backend) DecryptTxBlob(payload string) ([]*common.L2Tx, error) { return cleartextTxs, nil } -func (b *Backend) GetConfig() (*common.ObscuroNetworkInfo, error) { +func (b *Backend) GetConfig() (*common.TenNetworkInfo, error) { return b.obsClient.GetConfig() } From 68813df6ec967f8483c04fdbc14cd78c39f535c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=BDiga=20Kokelj?= Date: Fri, 9 Aug 2024 13:08:16 +0200 Subject: [PATCH 04/11] increase new heads timeout (#2014) --- tools/walletextension/rpcapi/wallet_extension.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/walletextension/rpcapi/wallet_extension.go b/tools/walletextension/rpcapi/wallet_extension.go index fae47871f7..518dd3c29b 100644 --- a/tools/walletextension/rpcapi/wallet_extension.go +++ b/tools/walletextension/rpcapi/wallet_extension.go @@ -147,7 +147,7 @@ func subscribeToNewHeadsWithRetry(ch chan *tencommon.BatchHeader, services Servi } return err }, - retry.NewTimeoutStrategy(10*time.Minute, 1*time.Second), + retry.NewTimeoutStrategy(20*time.Minute, 1*time.Second), ) if err != nil { logger.Error("could not subscribe for new head blocks.", log.ErrKey, err) From 9e72c760e78ff108fc9151a0d9745a485055362d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=BDiga=20Kokelj?= Date: Tue, 13 Aug 2024 14:03:48 +0200 Subject: [PATCH 05/11] remove file logger from the gateway (#2010) --- tools/walletextension/common/common.go | 13 ------------- tools/walletextension/rpcapi/utils.go | 2 +- tools/walletextension/rpcapi/wallet_extension.go | 3 --- 3 files changed, 1 insertion(+), 17 deletions(-) diff --git a/tools/walletextension/common/common.go b/tools/walletextension/common/common.go index a9a099b362..94ac8be729 100644 --- a/tools/walletextension/common/common.go +++ b/tools/walletextension/common/common.go @@ -3,9 +3,6 @@ package common import ( "encoding/json" "fmt" - "os" - - gethforklog "github.com/ten-protocol/go-ten/lib/gethfork/log" gethrpc "github.com/ten-protocol/go-ten/lib/gethfork/rpc" @@ -79,13 +76,3 @@ func (r *RPCRequest) Clone() *RPCRequest { Params: r.Params, } } - -// NewFileLogger is a logger factory function -func NewFileLogger() gethlog.Logger { - // Open or create your log file - file, err := os.OpenFile("gateway_logs.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o644) - if err != nil { - panic(err) - } - return gethlog.NewLogger(gethlog.NewGlogHandler(gethforklog.NewTerminalHandler(file, false))) -} diff --git a/tools/walletextension/rpcapi/utils.go b/tools/walletextension/rpcapi/utils.go index a90eacb810..732fd45d2e 100644 --- a/tools/walletextension/rpcapi/utils.go +++ b/tools/walletextension/rpcapi/utils.go @@ -265,7 +265,7 @@ func withCache[R any](cache cache.Cache, cfg *CacheCfg, cacheKey []byte, onCache func audit(services *Services, msg string, params ...any) { if services.Config.VerboseFlag { - services.FileLogger.Info(fmt.Sprintf(msg, params...)) + services.logger.Info(fmt.Sprintf(msg, params...)) } } diff --git a/tools/walletextension/rpcapi/wallet_extension.go b/tools/walletextension/rpcapi/wallet_extension.go index 518dd3c29b..726090d053 100644 --- a/tools/walletextension/rpcapi/wallet_extension.go +++ b/tools/walletextension/rpcapi/wallet_extension.go @@ -41,7 +41,6 @@ type Services struct { HostAddrWS string // The WS address on which the Ten host can be reached Storage storage.Storage logger gethlog.Logger - FileLogger gethlog.Logger stopControl *stopcontrol.StopControl version string Cache cache.Cache @@ -58,7 +57,6 @@ type NewHeadNotifier interface { } func NewServices(hostAddrHTTP string, hostAddrWS string, storage storage.Storage, stopControl *stopcontrol.StopControl, version string, logger gethlog.Logger, config *common.Config) *Services { - newFileLogger := common.NewFileLogger() newGatewayCache, err := cache.NewCache(logger) if err != nil { logger.Error(fmt.Errorf("could not create cache. Cause: %w", err).Error()) @@ -101,7 +99,6 @@ func NewServices(hostAddrHTTP string, hostAddrWS string, storage storage.Storage HostAddrWS: hostAddrWS, Storage: storage, logger: logger, - FileLogger: newFileLogger, stopControl: stopControl, version: version, Cache: newGatewayCache, From 1eb7c28eaa7af82e402f1cc247c421e6ae40a58e Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Tue, 13 Aug 2024 14:35:20 +0100 Subject: [PATCH 06/11] improve deadline error (#2015) * improve deadline error * rename --- go/enclave/nodetype/common.go | 2 +- tools/walletextension/rpcapi/transaction_api.go | 4 ++-- tools/walletextension/rpcapi/utils.go | 16 ++++++++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/go/enclave/nodetype/common.go b/go/enclave/nodetype/common.go index bff4a94447..c414f63c81 100644 --- a/go/enclave/nodetype/common.go +++ b/go/enclave/nodetype/common.go @@ -20,7 +20,7 @@ func ExportCrossChainData(ctx context.Context, storage storage.Storage, fromSeqN return nil, errutil.ErrCrossChainBundleNoBatches } - //todo - siliev - all those fetches need to be atomic + // todo - siliev - all those fetches need to be atomic header, err := storage.FetchHeadBatchHeader(ctx) if err != nil { return nil, err diff --git a/tools/walletextension/rpcapi/transaction_api.go b/tools/walletextension/rpcapi/transaction_api.go index 3833db0e77..a0a8baedd4 100644 --- a/tools/walletextension/rpcapi/transaction_api.go +++ b/tools/walletextension/rpcapi/transaction_api.go @@ -101,7 +101,7 @@ func (s *TransactionAPI) GetTransactionReceipt(ctx context.Context, hash common. } func (s *TransactionAPI) SendTransaction(ctx context.Context, args gethapi.TransactionArgs) (common.Hash, error) { - txRec, err := ExecAuthRPC[common.Hash](ctx, s.we, &ExecCfg{account: args.From}, "eth_sendTransaction", args) + txRec, err := ExecAuthRPC[common.Hash](ctx, s.we, &ExecCfg{account: args.From, timeout: sendTransactionDuration}, "eth_sendTransaction", args) if err != nil { return common.Hash{}, err } @@ -131,7 +131,7 @@ func (s *TransactionAPI) FillTransaction(ctx context.Context, args gethapi.Trans } func (s *TransactionAPI) SendRawTransaction(ctx context.Context, input hexutil.Bytes) (common.Hash, error) { - txRec, err := ExecAuthRPC[common.Hash](ctx, s.we, &ExecCfg{tryAll: true}, "eth_sendRawTransaction", input) + txRec, err := ExecAuthRPC[common.Hash](ctx, s.we, &ExecCfg{tryAll: true, timeout: sendTransactionDuration}, "eth_sendRawTransaction", input) if err != nil { return common.Hash{}, err } diff --git a/tools/walletextension/rpcapi/utils.go b/tools/walletextension/rpcapi/utils.go index 732fd45d2e..13d6197b2d 100644 --- a/tools/walletextension/rpcapi/utils.go +++ b/tools/walletextension/rpcapi/utils.go @@ -34,13 +34,15 @@ const ( ethCallAddrPadding = "000000000000000000000000" notAuthorised = "not authorised" + serverBusy = "server busy. please retry later" longCacheTTL = 5 * time.Hour shortCacheTTL = 1 * time.Minute // hardcoding the maximum time for an RPC request // this value will be propagated to the node and enclave and all the operations - maximumRPCCallDuration = 5 * time.Second + maximumRPCCallDuration = 5 * time.Second + sendTransactionDuration = 20 * time.Second ) var rpcNotImplemented = fmt.Errorf("rpc endpoint not implemented") @@ -52,6 +54,7 @@ type ExecCfg struct { tryUntilAuthorised bool adjustArgs func(acct *GWAccount) []any cacheCfg *CacheCfg + timeout time.Duration } type CacheStrategy uint8 @@ -136,10 +139,19 @@ func ExecAuthRPC[R any](ctx context.Context, w *Services, cfg *ExecCfg, method s } // wrap the context with a timeout to prevent long executions - timeoutContext, cancelCtx := context.WithTimeout(ctx, maximumRPCCallDuration) + deadline := cfg.timeout + // if not set, use default + if deadline == 0 { + deadline = maximumRPCCallDuration + } + timeoutContext, cancelCtx := context.WithTimeout(ctx, deadline) defer cancelCtx() err := rpcClient.CallContext(timeoutContext, &result, method, adjustedArgs...) + // return a friendly error to the user + if err != nil && errors.Is(err, context.DeadlineExceeded) { + return nil, fmt.Errorf(serverBusy) + } return result, err }) if err != nil { From 9b870e0b27752d2acda2a26acd8f61245721fbf0 Mon Sep 17 00:00:00 2001 From: Moray Grieve Date: Tue, 13 Aug 2024 15:06:00 +0100 Subject: [PATCH 07/11] Correct print output (#2019) * Correct print output * Remove whitespace --- tools/faucet/cmd/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/faucet/cmd/main.go b/tools/faucet/cmd/main.go index b865ceba1b..d22030eee5 100644 --- a/tools/faucet/cmd/main.go +++ b/tools/faucet/cmd/main.go @@ -29,7 +29,7 @@ func main() { if err != nil { panic(err) } - fmt.Printf("💡 Faucet started - visit http://%s/viewingkeys/ to generate an ephemeral viewing key.\n", cfg.Host) + fmt.Printf("💡 Faucet started on http://%s:%d\n", cfg.Host, cfg.HTTPPort) // Create a channel to receive signals signalCh := make(chan os.Signal, 1) From f692c2692615c610e7722d63ebfcbe1463236eee Mon Sep 17 00:00:00 2001 From: badgersrus <43809877+badgersrus@users.noreply.github.com> Date: Tue, 13 Aug 2024 17:17:10 +0200 Subject: [PATCH 08/11] change network test port (#2018) switch the network test port --- integration/constants.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/integration/constants.go b/integration/constants.go index ace11bc1da..386599e773 100644 --- a/integration/constants.go +++ b/integration/constants.go @@ -3,20 +3,20 @@ package integration // Tracks the start ports handed out to different tests, in a bid to minimise conflicts. // Note: the max should not exceed 30000 because the OS can use those ports and we'll get conflicts const ( - StartPortEth2NetworkTests = 10000 - StartPortTenscanUnitTest = 11000 - StartPortNodeRunnerTest = 12000 - StartPortSimulationGethInMem = 14000 - StartPortSimulationInMem = 15000 - StartPortSimulationFullNetwork = 16000 - StartPortNetworkTests = 17000 - StartPortSmartContractTests = 18000 - StartPortContractDeployerTest1 = 19000 - StartPortContractDeployerTest2 = 21000 - StartPortFaucetUnitTest = 22000 - StartPortFaucetHTTPUnitTest = 23000 - StartPortTenGatewayUnitTest = 24000 - StartPortWalletExtensionUnitTest = 25000 + StartPortEth2NetworkTests = 10000 + StartPortTenscanUnitTest = 11000 + StartPortNodeRunnerTest = 12000 + StartPortSimulationGethInMem = 14000 + StartPortSimulationInMem = 15000 + StartPortSimulationFullNetwork = 16000 + DoNotUse = 17000 // port conflict on this address + StartPortSmartContractTests = 18000 + StartPortContractDeployerTest1 = 19000 + StartPortContractDeployerTest2 = 21000 + StartPortFaucetUnitTest = 22000 + StartPortFaucetHTTPUnitTest = 23000 + StartPortTenGatewayUnitTest = 24000 + StartPortNetworkTests = 25000 DefaultGethWSPortOffset = 100 DefaultGethAUTHPortOffset = 200 From 86ee410669869d4f9161418892c14d0005f23aca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=BDiga=20Kokelj?= Date: Tue, 13 Aug 2024 17:46:18 +0200 Subject: [PATCH 09/11] Add network config endpoint (#2016) --- tools/walletextension/common/constants.go | 1 + tools/walletextension/httpapi/routes.go | 55 +++++++++++++++++++ .../rpcapi/wallet_extension.go | 8 +++ 3 files changed, 64 insertions(+) diff --git a/tools/walletextension/common/constants.go b/tools/walletextension/common/constants.go index 3fdb4d63a2..5b72b8ee35 100644 --- a/tools/walletextension/common/constants.go +++ b/tools/walletextension/common/constants.go @@ -24,6 +24,7 @@ const ( PathRevoke = "/revoke/" PathHealth = "/health/" PathNetworkHealth = "/network-health/" + PathNetworkConfig = "/network-config/" WSProtocol = "ws://" HTTPProtocol = "http://" EncryptedTokenQueryParameter = "token" diff --git a/tools/walletextension/httpapi/routes.go b/tools/walletextension/httpapi/routes.go index abb8f9573a..cbdb5baf8e 100644 --- a/tools/walletextension/httpapi/routes.go +++ b/tools/walletextension/httpapi/routes.go @@ -58,6 +58,10 @@ func NewHTTPRoutes(walletExt *rpcapi.Services) []node.Route { Name: common.APIVersion1 + common.PathVersion, Func: httpHandler(walletExt, versionRequestHandler), }, + { + Name: common.APIVersion1 + common.PathNetworkConfig, + Func: httpHandler(walletExt, networkConfigRequestHandler), + }, } } @@ -317,6 +321,57 @@ func networkHealthRequestHandler(walletExt *rpcapi.Services, userConn UserConn) } } +func networkConfigRequestHandler(walletExt *rpcapi.Services, userConn UserConn) { + // read the request + _, err := userConn.ReadRequest() + if err != nil { + walletExt.Logger().Error("error reading request", log.ErrKey, err) + return + } + + // Call the RPC method to get the network configuration + networkConfig, err := walletExt.GetTenNetworkConfig() + if err != nil { + walletExt.Logger().Error("error fetching network config", log.ErrKey, err) + } + + // Define a struct to represent the response + type NetworkConfigResponse struct { + ManagementContractAddress string `json:"ManagementContractAddress"` + L1StartHash string `json:"L1StartHash"` + MessageBusAddress string `json:"MessageBusAddress"` + L2MessageBusAddress string `json:"L2MessageBusAddress"` + ImportantContracts map[string]string `json:"ImportantContracts"` + } + + // Convert the TenNetworkInfo fields to strings + importantContracts := make(map[string]string) + for name, address := range networkConfig.ImportantContracts { + importantContracts[name] = address.Hex() + } + + networkConfigResponse := NetworkConfigResponse{ + ManagementContractAddress: networkConfig.ManagementContractAddress.Hex(), + L1StartHash: networkConfig.L1StartHash.Hex(), + MessageBusAddress: networkConfig.MessageBusAddress.Hex(), + L2MessageBusAddress: networkConfig.L2MessageBusAddress.Hex(), + ImportantContracts: importantContracts, + } + + // Marshal the response into JSON format + data, err := json.Marshal(networkConfigResponse) + if err != nil { + walletExt.Logger().Error("error marshaling response", log.ErrKey, err) + return + } + + // Write the response back to the user + err = userConn.WriteResponse(data) + if err != nil { + walletExt.Logger().Error("error writing success response", log.ErrKey, err) + } +} + // Handles request to /version endpoint. func versionRequestHandler(walletExt *rpcapi.Services, userConn UserConn) { // read the request diff --git a/tools/walletextension/rpcapi/wallet_extension.go b/tools/walletextension/rpcapi/wallet_extension.go index 726090d053..6d7c036b85 100644 --- a/tools/walletextension/rpcapi/wallet_extension.go +++ b/tools/walletextension/rpcapi/wallet_extension.go @@ -280,6 +280,14 @@ func (w *Services) GetTenNodeHealthStatus() (bool, error) { return *res, err } +func (w *Services) GetTenNetworkConfig() (tencommon.TenNetworkInfo, error) { + res, err := withPlainRPCConnection[tencommon.TenNetworkInfo](context.Background(), w, func(client *gethrpc.Client) (*tencommon.TenNetworkInfo, error) { + res, err := obsclient.NewObsClient(client).GetConfig() + return res, err + }) + return *res, err +} + func (w *Services) GenerateUserMessageToSign(encryptionToken []byte, formatsSlice []string) (string, error) { // Check if the formats are valid for _, format := range formatsSlice { From 4a20b1024b4234a761df1659464c2534cfa3bb9c Mon Sep 17 00:00:00 2001 From: Jennifer Echenim Date: Wed, 14 Aug 2024 12:21:35 +0400 Subject: [PATCH 10/11] Update environment variables in manual-deploy-ten-bridge.yml and Dockerfile --- .github/workflows/manual-deploy-ten-bridge.yml | 2 +- contracts/src/bridge/frontend/Dockerfile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/manual-deploy-ten-bridge.yml b/.github/workflows/manual-deploy-ten-bridge.yml index a6ab57c4b2..e5ab7feb69 100644 --- a/.github/workflows/manual-deploy-ten-bridge.yml +++ b/.github/workflows/manual-deploy-ten-bridge.yml @@ -58,7 +58,7 @@ jobs: name: ${{ github.event.inputs.testnet_type }}-fe-ten-bridge location: "uksouth" restart-policy: "Never" - environment-variables: NEXT_PUBLIC_BRIDGE_API_HOST_ENVIRONMENT=${{ github.event.inputs.testnet_type }} NEXT_PUBLIC_FE_VERSION=${{ GITHUB.RUN_NUMBER }}-${{ GITHUB.SHA }} + environment-variables: NEXT_PUBLIC_BRIDGE_API_HOST=https://${{ github.event.inputs.testnet_type }}.ten.xyz/v1 NEXT_PUBLIC_FE_VERSION=${{ GITHUB.RUN_NUMBER }}-${{ GITHUB.SHA }} command-line: npm run start-prod ports: "80" cpu: 2 diff --git a/contracts/src/bridge/frontend/Dockerfile b/contracts/src/bridge/frontend/Dockerfile index 1618f5b024..0b68092cf4 100644 --- a/contracts/src/bridge/frontend/Dockerfile +++ b/contracts/src/bridge/frontend/Dockerfile @@ -8,11 +8,11 @@ COPY ./contracts/src/bridge/frontend /home/obscuro/go-obscuro/contracts/src/brid WORKDIR /home/obscuro/go-obscuro/contracts/src/bridge/frontend # ARG for build-time variable -ARG BRIDGE_ENVIRONMENT +ARG API_HOST ARG GOOGLE_ANALYTICS_ID # ENV for URL to be used in the app -ENV NEXT_PUBLIC_BRIDGE_API_HOST_ENVIRONMENT=${BRIDGE_ENVIRONMENT} +ENV NEXT_PUBLIC_BRIDGE_API_HOST=${API_HOST} ENV NEXT_PUBLIC_BRIDGE_GOOGLE_ANALYTICS_ID=${GOOGLE_ANALYTICS_ID} RUN npm install From c10cbf279f2aa918aba317a06e96ae2837fe579d Mon Sep 17 00:00:00 2001 From: Moray Grieve Date: Wed, 14 Aug 2024 09:28:56 +0100 Subject: [PATCH 11/11] Additions to the change log (#2020) * More changes * Latest changes --- changelog.md | 55 +++++++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/changelog.md b/changelog.md index 5cccebdc59..f687f7d2ab 100644 --- a/changelog.md +++ b/changelog.md @@ -3,31 +3,38 @@ # Ten Testnet Change Log # August 2024-08-08 (v0.26.0) -* This is an L2 deployment release meaning state will be lost in order to upgrade the network. The release - predominantly fixes known minor issues in the network, including issues deploying and interacting - with contracts using ethers6, and extracting event logs from tx receipts for bridge operations. +* This is an L2 deployment release meaning state will be lost in order to upgrade the network. The release adds in + rate limiting to the TEN gateway, support for using proxy deployments, and for using the ethers6 web3 library. * A full list of the PRs merged in this release is as below; - * `db6e507e` Revert refactor event log filtering for subscriptions (#2013) - * `b043708a` Initiate bridge deployment (#2012) - * `475b7057` Disable rate limiting on local testnet (#2005) - * `86418f6d` Stopped returning errors on republish. (#2008) - * `396c113d` Only configure docker autorestart on the main containers (#2007) - * `e30e4eaa` Filter out irrelevant l1 txs, before sending into the enclave (#2006) - * `7b62b2e4` Revert message address indexing (#2002) - * `65d96465` Add dummy fields to keep ethers6 happy (#2003) - * `c3ad0a44` Fix for dependency (#2000) - * `3f7f12f9` Implement mock maxpriorityfeepergas (#1999) - * `9e91e5c2` Add ten headers (#1998) - * `ad61bdb0` Gateway rate limiting (#1942) - * `9bd08a23` Fix getblock rpc (#1997) - * `ec5315b6` Personal transaction/contract deployment details page (#1990) - * `97792e4e` Getstorageat with whitelist for proxies deployment (#1987) - * `e9b29779` Allow cors all origins to fix firefox error (#1991) - * `b13272b3` Replace custom query with personal transactions (#1986) - * `81ad4043` Refactor event log filtering for subscriptions (#1988) - * `6a4bc5b9` Fix event sql query (#1984) - * `a3a901bf` Frontend updates (#1932) - * `3b75a255` Block binding fix (#1982) + * `86ee4106` Add network config endpoint (#2016) + * `f692c269` Change network test port (#2018) + * `9b870e0b` Correct print output of the faucet (#2019) + * `1eb7c28e` Improve deadline error (#2015) + * `9e72c760` Remove file logger from the gateway (#2010) + * `68813df6` Increase new heads timeout (#2014) + * `3846fa56` Upgrade local geth version to pos (#1950) + * `d32dfda7` Change log for v0.26 (#2011) + * `db6e507e` Revert refactor event log filtering for subscriptions (#2013) + * `b043708a` Initiate bridge deployment (#2012) + * `475b7057` Disable rate limiting on local testnet (#2005) + * `86418f6d` Stopped returning errors on republish. (#2008) + * `396c113d` Only configure docker autorestart on the main containers (#2007) + * `e30e4eaa` Filter out irrelevant l1 txs, before sending into the enclave (#2006) + * `7b62b2e4` Revert message address indexing (#2002) + * `65d96465` Add dummy fields to keep ethers6 happy (#2003) + * `c3ad0a44` Fix for dependency (#2000) + * `3f7f12f9` Implement mock maxpriorityfeepergas (#1999) + * `9e91e5c2` Add ten headers (#1998) + * `ad61bdb0` Gateway rate limiting (#1942) + * `9bd08a23` Fix getblock rpc (#1997) + * `ec5315b6` Personal transaction/contract deployment details page (#1990) + * `97792e4e` Getstorageat with whitelist for proxies deployment (#1987) + * `e9b29779` Allow cors all origins to fix firefox error (#1991) + * `b13272b3` Replace custom query with personal transactions (#1986) + * `81ad4043` Refactor event log filtering for subscriptions (#1988) + * `6a4bc5b9` Fix event sql query (#1984) + * `a3a901bf` Frontend updates (#1932) + * `3b75a255` Block binding fix (#1982) # July 2024-07-03 (v0.25.0) * This is an L2 deployment release meaning state will be lost in order to upgrade the network. Any dApps on the