From 27d1634b5baba528776466168841836a92d8b08d Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Wed, 7 Aug 2024 04:50:53 +0000 Subject: [PATCH] Fix RPC for blob transactions (#266) - Fixes RPC for blob transactions - Allows loading chain ID from chain config file, improving integration in https://git.vdb.to/cerc-io/fixturenet-eth-stacks/pulls/21 Depends on https://git.vdb.to/cerc-io/system-tests/pulls/13 Reviewed-on: https://git.vdb.to/cerc-io/ipld-eth-server/pulls/266 --- .dockerignore | 1 + .github/workflows/tests.yaml | 11 +++++++--- Dockerfile | 4 ---- cmd/serve.go | 4 ++-- entrypoint.sh | 11 +--------- environments/testing.toml | 2 +- pkg/eth/api.go | 6 ++++++ pkg/serve/config.go | 39 +++++++++++++++++++++++++----------- scripts/run-test-stack.sh | 8 ++++++-- test/compose-db.yml | 2 +- test/compose-server.yml | 2 ++ 11 files changed, 55 insertions(+), 35 deletions(-) diff --git a/.dockerignore b/.dockerignore index ed36ad3f..c4aee257 100644 --- a/.dockerignore +++ b/.dockerignore @@ -12,6 +12,7 @@ integration test scripts Dockerfile +environments **/node_modules build \ No newline at end of file diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 87c59c0b..d778fbf4 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -102,10 +102,15 @@ jobs: progress: false - name: Run system tests working-directory: ./system-tests + # Work around dependency conflict in system-tests: + # web3 uses an older eth-account until (unreleased) v7 run: | - pip install pytest - pip install -r requirements.txt - pytest -vv + pip3 install pytest + pip3 install -r requirements.txt + pip3 install --no-deps 'eth-account>=0.12.3,<0.13' + pip3 install 'pydantic>=2.0.0' + # Skips tests that require Blob indexing + python3 -m pytest -vv -m "not blob_db" - name: Run testnet stack without statediff env: diff --git a/Dockerfile b/Dockerfile index 7ce3ca05..e9804da1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,7 +29,6 @@ RUN GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' - FROM alpine ARG USER="vdm" -ARG CONFIG_FILE="./environments/example.toml" RUN adduser -Du 5000 $USER WORKDIR /app @@ -38,13 +37,10 @@ USER $USER # chown first so dir is writable # note: using $USER is merged, but not in the stable release yet -COPY --chown=5000:5000 --from=builder /go/src/github.com/cerc-io/ipld-eth-server/$CONFIG_FILE config.toml COPY --chown=5000:5000 --from=builder /go/src/github.com/cerc-io/ipld-eth-server/entrypoint.sh . - # keep binaries immutable COPY --from=builder /go/src/github.com/cerc-io/ipld-eth-server/ipld-eth-server ipld-eth-server -COPY --from=builder /go/src/github.com/cerc-io/ipld-eth-server/environments environments # Allow for debugging COPY --from=debugger /go/bin/dlv /usr/local/bin/ diff --git a/cmd/serve.go b/cmd/serve.go index 7d94cbf3..cc3345b2 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -277,10 +277,10 @@ func init() { serveCmd.PersistentFlags().String("eth-client-name", "Geth", "eth client name") serveCmd.PersistentFlags().String("eth-genesis-block", "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3", "eth genesis block hash") serveCmd.PersistentFlags().String("eth-network-id", "1", "eth network id") - serveCmd.PersistentFlags().String("eth-chain-id", "1", "eth chain id") + serveCmd.PersistentFlags().String("eth-chain-id", "", "eth chain id") + serveCmd.PersistentFlags().String("eth-chain-config", "", "json chain config file location") serveCmd.PersistentFlags().String("eth-default-sender", "", "default sender address") serveCmd.PersistentFlags().String("eth-rpc-gas-cap", "", "rpc gas cap (for eth_Call execution)") - serveCmd.PersistentFlags().String("eth-chain-config", "", "json chain config file location") serveCmd.PersistentFlags().Bool("eth-supports-state-diff", false, "whether the proxy ethereum client supports statediffing endpoints") serveCmd.PersistentFlags().Bool("eth-forward-eth-calls", false, "whether to immediately forward eth_calls to proxy client") serveCmd.PersistentFlags().Bool("eth-proxy-on-error", true, "whether to forward all failed calls to proxy client") diff --git a/entrypoint.sh b/entrypoint.sh index 109736c4..0d09070a 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,17 +1,8 @@ #!/bin/sh -echo "Beginning the ipld-eth-server process" - START_CMD="./ipld-eth-server" if [ "true" == "$CERC_REMOTE_DEBUG" ] && [ -x "/usr/local/bin/dlv" ]; then START_CMD="/usr/local/bin/dlv --listen=:40000 --headless=true --api-version=2 --accept-multiclient exec `pwd`/ipld-eth-server --continue --" fi -echo running: $START_CMD ${VDB_COMMAND} --config=`pwd`/config.toml -$START_CMD ${VDB_COMMAND} --config=`pwd`/config.toml -rv=$? - -if [ $rv != 0 ]; then - echo "ipld-eth-server startup failed" - exit 1 -fi \ No newline at end of file +exec $START_CMD ${VDB_COMMAND:-serve} diff --git a/environments/testing.toml b/environments/testing.toml index 6552cedb..a04c594b 100644 --- a/environments/testing.toml +++ b/environments/testing.toml @@ -1,5 +1,5 @@ [database] - name = "vulcanize_testing" + name = "cerc_testing" hostname = "localhost" port = 5432 diff --git a/pkg/eth/api.go b/pkg/eth/api.go index 6adcc901..57e5e745 100644 --- a/pkg/eth/api.go +++ b/pkg/eth/api.go @@ -660,6 +660,12 @@ func (pea *PublicEthAPI) localGetTransactionReceipt(ctx context.Context, hash co if receipt.Logs == nil { fields["logs"] = []*types.Log{} } + + if tx.Type() == types.BlobTxType { + fields["blobGasUsed"] = hexutil.Uint64(receipt.BlobGasUsed) + fields["blobGasPrice"] = (*hexutil.Big)(receipt.BlobGasPrice) + } + // If the ContractAddress is 20 0x0 bytes, assume it is not a contract creation if receipt.ContractAddress != (common.Address{}) { fields["contractAddress"] = receipt.ContractAddress diff --git a/pkg/serve/config.go b/pkg/serve/config.go index 7c12b3bb..cbc12a3f 100644 --- a/pkg/serve/config.go +++ b/pkg/serve/config.go @@ -128,9 +128,10 @@ func NewConfig() (*Config, error) { viper.BindEnv("server.ipcPath", SERVER_IPC_PATH) viper.BindEnv("server.graphqlPath", SERVER_GRAPHQL_PATH) + viper.BindEnv("ethereum.chainID", ETH_CHAIN_ID) + viper.BindEnv("ethereum.chainConfig", ETH_CHAIN_CONFIG) viper.BindEnv("ethereum.httpPath", ETH_HTTP_PATH) viper.BindEnv("ethereum.rpcGasCap", ETH_RPC_GAS_CAP) - viper.BindEnv("ethereum.chainConfig", ETH_CHAIN_CONFIG) viper.BindEnv("ethereum.supportsStateDiff", ETH_SUPPORTS_STATEDIFF) viper.BindEnv("ethereum.stateDiffTimeout", ETH_STATEDIFF_TIMEOUT) viper.BindEnv("ethereum.forwardEthCalls", ETH_FORWARD_ETH_CALLS) @@ -143,11 +144,32 @@ func NewConfig() (*Config, error) { c.dbInit() ethHTTP := viper.GetString("ethereum.httpPath") ethHTTPEndpoint := fmt.Sprintf("http://%s", ethHTTP) - nodeInfo, cli, err := getEthNodeAndClient(ethHTTPEndpoint) - c.NodeNetworkID = nodeInfo.NetworkID + + // At least one of chain ID and chain config must be passed. + // If both are passed, the chain ID must match the config. + chainID := viper.GetUint64("ethereum.chainID") + chainConfigPath := viper.GetString("ethereum.chainConfig") + var err error + if chainConfigPath != "" { + if c.ChainConfig, err = utils.LoadConfig(chainConfigPath); err != nil { + return nil, err + } + // Only validate the chain ID if it was actually passed + if viper.GetString("ethereum.chainID") != "" && c.ChainConfig.ChainID.Uint64() != chainID { + return nil, fmt.Errorf("passed chain ID %d does not match chain config chain ID %d", + chainID, c.ChainConfig.ChainID.Uint64()) + } + } else { + if c.ChainConfig, err = utils.ChainConfig(chainID); err != nil { + return nil, err + } + } + + nodeInfo, cli, err := getEthNodeAndClient(ethHTTPEndpoint, chainID) if err != nil { return nil, err } + c.NodeNetworkID = nodeInfo.NetworkID c.Client = cli c.SupportStateDiff = viper.GetBool("ethereum.supportsStateDiff") c.ForwardEthCalls = viper.GetBool("ethereum.forwardEthCalls") @@ -237,12 +259,6 @@ func NewConfig() (*Config, error) { if c.StateDiffTimeout < 0 { return nil, errors.New("ethereum.stateDiffTimeout < 0") } - chainConfigPath := viper.GetString("ethereum.chainConfig") - if chainConfigPath != "" { - c.ChainConfig, err = utils.LoadConfig(chainConfigPath) - } else { - c.ChainConfig, err = utils.ChainConfig(nodeInfo.ChainID) - } c.loadGroupCacheConfig() @@ -312,12 +328,11 @@ func (c *Config) loadValidatorConfig() { } // GetEthNodeAndClient returns eth node info and client from path url -func getEthNodeAndClient(path string) (node.Info, *rpc.Client, error) { +func getEthNodeAndClient(path string, chainid uint64) (node.Info, *rpc.Client, error) { viper.BindEnv("ethereum.nodeID", ETH_NODE_ID) viper.BindEnv("ethereum.clientName", ETH_CLIENT_NAME) viper.BindEnv("ethereum.genesisBlock", ETH_GENESIS_BLOCK) viper.BindEnv("ethereum.networkID", ETH_NETWORK_ID) - viper.BindEnv("ethereum.chainID", ETH_CHAIN_ID) rpcClient, err := rpc.Dial(path) if err != nil { @@ -328,6 +343,6 @@ func getEthNodeAndClient(path string) (node.Info, *rpc.Client, error) { ClientName: viper.GetString("ethereum.clientName"), GenesisBlock: viper.GetString("ethereum.genesisBlock"), NetworkID: viper.GetString("ethereum.networkID"), - ChainID: viper.GetUint64("ethereum.chainID"), + ChainID: chainid, }, rpcClient, nil } diff --git a/scripts/run-test-stack.sh b/scripts/run-test-stack.sh index 3328b09d..dea771fb 100755 --- a/scripts/run-test-stack.sh +++ b/scripts/run-test-stack.sh @@ -22,11 +22,15 @@ if [[ -z $SKIP_BUILD ]]; then # Prevent conflicting tty output export BUILDKIT_PROGRESS=plain - $laconic_so setup-repositories - $laconic_so build-containers + # The server itself will be run separately + $laconic_so setup-repositories \ + --exclude git.vdb.to/cerc-io/ipld-eth-server + $laconic_so build-containers \ + --exclude cerc/ipld-eth-server fi if ! $laconic_so deploy \ + --exclude ipld-eth-server \ --env-file $CONFIG_DIR/stack.env \ --cluster test up then diff --git a/test/compose-db.yml b/test/compose-db.yml index ab9d7666..bdb4f8d4 100644 --- a/test/compose-db.yml +++ b/test/compose-db.yml @@ -5,7 +5,7 @@ services: restart: on-failure depends_on: - ipld-eth-db - image: git.vdb.to/cerc-io/ipld-eth-db/ipld-eth-db:v5.3.0-alpha + image: git.vdb.to/cerc-io/ipld-eth-db/ipld-eth-db:v5.4.0-alpha environment: DATABASE_USER: "vdbm" DATABASE_NAME: "cerc_testing" diff --git a/test/compose-server.yml b/test/compose-server.yml index 2aa8bdb5..b7d5409b 100644 --- a/test/compose-server.yml +++ b/test/compose-server.yml @@ -4,6 +4,8 @@ services: ipld-eth-server: restart: unless-stopped image: cerc/ipld-eth-server:local + build: + context: .. networks: - test_default environment: