Skip to content

Commit adbbb1a

Browse files
manav2401claude
andauthored
feat(evmonly): add eth_getVMError, eth_getTransactionErrorByHash and web3_clientVersion to the EVM-only RPC (#4667)
This PR adds 3 new RPC methods - `eth_getVMError`: returns the EVM error stored on a finalized transaction's receipt, or "" if it succeeded. An unknown hash returns a "receipt not found" error, as on the regular RPC. - `eth_getTransactionErrorByHash`: returns the same stored EVM error. An unknown hash returns "" instead of an error, as on the regular RPC. - `web3_clientVersion`: returns `Sei/<seid version>/<os>-<arch>/<go version>`. The v2 RPC is unchanged and still reports `Geth/` prefix followed by other things. Test coverage: RPC handler tests and new checks in the Autobahn Basic suite. --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ba611f0 commit adbbb1a

7 files changed

Lines changed: 259 additions & 9 deletions

File tree

‎giga/evmonly/rpc/server.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ func newHandler(backend Backend, receiptStore receipt.ReceiptStore, limits gigac
174174
if err := rpcServer.RegisterName("net", &netAPI{backend: backend}); err != nil {
175175
return nil, fmt.Errorf("register EVM-only net RPC: %w", err)
176176
}
177+
if err := rpcServer.RegisterName("web3", &web3API{}); err != nil {
178+
return nil, fmt.Errorf("register EVM-only web3 RPC: %w", err)
179+
}
177180
subscriptions := newSubscriptionLimiter(limits.MaxSubscriptionsNewHead, limits.MaxSubscriptionsPerConnection)
178181
if err := rpcServer.RegisterName("eth", &subscribeAPI{backend: backend, store: receiptStore, limits: subscriptions}); err != nil {
179182
return nil, fmt.Errorf("register EVM-only subscription RPC: %w", err)

‎giga/evmonly/rpc/tx.go‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,29 @@ func (api *txAPI) GetTransactionByHash(ctx context.Context, hash common.Hash) (*
8787
return result, nil
8888
}
8989

90+
// GetVMError returns the EVM error hash's transaction failed with, or "" when it
91+
// succeeded. It returns an error when hash has no finalized receipt.
92+
func (api *txAPI) GetVMError(ctx context.Context, hash common.Hash) (string, error) {
93+
stored, _, err := api.lookupFinalizedTx(ctx, hash)
94+
if err != nil {
95+
return "", err
96+
}
97+
if stored == nil {
98+
return "", receiptpkg.ErrNotFound
99+
}
100+
return stored.VmError, nil
101+
}
102+
103+
// GetTransactionErrorByHash returns the EVM error hash's transaction failed with,
104+
// or "" when it succeeded or has no finalized receipt.
105+
func (api *txAPI) GetTransactionErrorByHash(ctx context.Context, hash common.Hash) (string, error) {
106+
stored, _, err := api.lookupFinalizedTx(ctx, hash)
107+
if err != nil || stored == nil {
108+
return "", err
109+
}
110+
return stored.VmError, nil
111+
}
112+
90113
// lookupFinalizedTx resolves hash's stored receipt and finalized block. It
91114
// returns a nil receipt with a nil error when hash is unknown or its block is
92115
// not yet finalized.

‎giga/evmonly/rpc/tx_test.go‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,3 +722,77 @@ func TestGetTransactionReceiptIncludesContractAddressAndSkipsNilLogs(t *testing.
722722
require.Equal(t, &created, got["contractAddress"])
723723
require.Empty(t, got["logs"])
724724
}
725+
726+
func TestTransactionErrorMethods(t *testing.T) {
727+
failed, succeeded, unfinalized := common.Hash{1}, common.Hash{2}, common.Hash{3}
728+
store := evmonly.NewMemoryReceiptStore()
729+
require.NoError(t, store.SetReceipts(sdk.Context{}.WithContext(t.Context()), []receipt.ReceiptRecord{
730+
{TxHash: failed, Receipt: &evmtypes.Receipt{TxHashHex: failed.Hex(), BlockNumber: 7, VmError: "execution reverted"}},
731+
{TxHash: succeeded, Receipt: &evmtypes.Receipt{TxHashHex: succeeded.Hex(), BlockNumber: 7}},
732+
{TxHash: unfinalized, Receipt: &evmtypes.Receipt{TxHashHex: unfinalized.Hex(), BlockNumber: 8}},
733+
}))
734+
backend := &testBackend{
735+
block: func(_ context.Context, req *coretypes.RequestBlockInfo) (*coretypes.ResultBlock, error) {
736+
if *req.Height > 7 {
737+
return nil, fmt.Errorf("%w: %d", coretypes.ErrHeightExceedsChainHead, *req.Height)
738+
}
739+
return &coretypes.ResultBlock{Block: &tmtypes.Block{}}, nil
740+
},
741+
}
742+
handler, err := newHandler(backend, store, noRPCLimits)
743+
require.NoError(t, err)
744+
t.Cleanup(handler.Stop)
745+
server := httptest.NewServer(handler)
746+
t.Cleanup(server.Close)
747+
client, err := ethrpc.DialHTTP(server.URL)
748+
require.NoError(t, err)
749+
t.Cleanup(client.Close)
750+
751+
for _, tc := range []struct {
752+
name string
753+
hash common.Hash
754+
want string
755+
notFound bool
756+
}{
757+
{name: "failed transaction", hash: failed, want: "execution reverted"},
758+
{name: "successful transaction", hash: succeeded, want: ""},
759+
{name: "unknown hash", hash: common.Hash{9}, notFound: true},
760+
{name: "block not finalized", hash: unfinalized, notFound: true},
761+
} {
762+
t.Run(tc.name, func(t *testing.T) {
763+
var byHash string
764+
require.NoError(t, client.CallContext(t.Context(), &byHash, "eth_getTransactionErrorByHash", tc.hash))
765+
require.Equal(t, tc.want, byHash)
766+
767+
var vmError string
768+
err := client.CallContext(t.Context(), &vmError, "eth_getVMError", tc.hash)
769+
if tc.notFound {
770+
require.ErrorContains(t, err, receipt.ErrNotFound.Error())
771+
return
772+
}
773+
require.NoError(t, err)
774+
require.Equal(t, tc.want, vmError)
775+
})
776+
}
777+
}
778+
779+
func TestTransactionErrorMethodsSurfaceStoreErrors(t *testing.T) {
780+
storeErr := errors.New("store unavailable")
781+
api := &txAPI{backend: &testBackend{}, store: stubReceiptStore{
782+
get: func(sdk.Context, common.Hash) (*evmtypes.Receipt, error) { return nil, storeErr },
783+
}}
784+
785+
for _, tc := range []struct {
786+
name string
787+
method func(context.Context, common.Hash) (string, error)
788+
}{
789+
{name: "eth_getVMError", method: api.GetVMError},
790+
{name: "eth_getTransactionErrorByHash", method: api.GetTransactionErrorByHash},
791+
} {
792+
t.Run(tc.name, func(t *testing.T) {
793+
got, err := tc.method(t.Context(), common.Hash{1})
794+
require.ErrorIs(t, err, storeErr)
795+
require.Empty(t, got)
796+
})
797+
}
798+
}

‎giga/evmonly/rpc/web3.go‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package rpc
2+
3+
import (
4+
"runtime"
5+
6+
"github.com/sei-protocol/sei-chain/sei-cosmos/version"
7+
)
8+
9+
type web3API struct{}
10+
11+
// ClientVersion returns the node's client identifier, Sei/<seid version>/<os>-<arch>/<go version>.
12+
// The version is "unknown" when the binary was built without one.
13+
func (*web3API) ClientVersion() string {
14+
v := version.Version
15+
if v == "" {
16+
v = "unknown"
17+
}
18+
return "Sei/" + v + "/" + runtime.GOOS + "-" + runtime.GOARCH + "/" + runtime.Version()
19+
}

‎giga/evmonly/rpc/web3_test.go‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package rpc
2+
3+
import (
4+
"net/http/httptest"
5+
"runtime"
6+
"testing"
7+
8+
ethrpc "github.com/ethereum/go-ethereum/rpc"
9+
"github.com/stretchr/testify/require"
10+
11+
"github.com/sei-protocol/sei-chain/giga/evmonly"
12+
"github.com/sei-protocol/sei-chain/sei-cosmos/version"
13+
)
14+
15+
func TestHandlerServesClientVersion(t *testing.T) {
16+
handler, err := newHandler(&testBackend{}, evmonly.NewMemoryReceiptStore(), noRPCLimits)
17+
require.NoError(t, err)
18+
t.Cleanup(handler.Stop)
19+
server := httptest.NewServer(handler)
20+
t.Cleanup(server.Close)
21+
client, err := ethrpc.DialHTTP(server.URL)
22+
require.NoError(t, err)
23+
t.Cleanup(client.Close)
24+
platform := runtime.GOOS + "-" + runtime.GOARCH + "/" + runtime.Version()
25+
26+
for _, tc := range []struct {
27+
name string
28+
version string
29+
want string
30+
}{
31+
{name: "built with a version", version: "v6.7.0", want: "Sei/v6.7.0/" + platform},
32+
{name: "built without a version", version: "", want: "Sei/unknown/" + platform},
33+
} {
34+
t.Run(tc.name, func(t *testing.T) {
35+
original := version.Version
36+
t.Cleanup(func() { version.Version = original })
37+
version.Version = tc.version
38+
39+
var got string
40+
require.NoError(t, client.CallContext(t.Context(), &got, "web3_clientVersion"))
41+
require.Equal(t, tc.want, got)
42+
})
43+
}
44+
}

‎integration_test/autobahn/README.md‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ WebSocket (port 8546 by default):
378378
and `eth_getTransactionByBlockNumberAndIndex` /
379379
`eth_getTransactionByBlockHashAndIndex`, which return the transaction at a
380380
position in a block exactly as the full-transaction block lists it.
381+
`eth_getVMError` and `eth_getTransactionErrorByHash` return the EVM error a
382+
finalized transaction failed with, or `""` when it succeeded; for an unknown
383+
hash the first returns an error and the second `""`, as on the regular RPC.
381384
- State: `eth_getBalance`, `eth_getTransactionCount`, `eth_getCode`, and
382385
`eth_getStorageAt`, at the latest block or a past one still within a full
383386
node's retention window; `eth_call` and `eth_estimateGas`, against the
@@ -393,8 +396,10 @@ WebSocket (port 8546 by default):
393396
yet returns `null`.
394397
- Logs: `eth_getLogs`.
395398
- Fees: `eth_gasPrice`, `eth_maxPriorityFeePerGas`, and `eth_feeHistory`.
396-
- Node: `eth_chainId`, `net_version`, and `eth_syncing`, which returns a
397-
not-supported error, as on the regular RPC.
399+
- Node: `eth_chainId`, `net_version`, `web3_clientVersion`, which returns
400+
`Sei/<seid version>/<os>-<arch>/<go version>` (the regular RPC reports
401+
`Geth/...`), and `eth_syncing`, which returns a not-supported error, as on the
402+
regular RPC.
398403
- Tracing: `debug_traceTransaction`, `debug_traceCall`,
399404
`debug_traceBlockByNumber`, and `debug_traceBlockByHash`, with
400405
go-ethereum's tracers (see
@@ -409,8 +414,7 @@ subscription other than `newHeads`:
409414
the polling filter methods (`eth_newFilter`, `eth_newBlockFilter`,
410415
`eth_newPendingTransactionFilter`, `eth_getFilterChanges`,
411416
`eth_getFilterLogs`, `eth_uninstallFilter`), `eth_subscribe("logs")`,
412-
`eth_getVMError`, `eth_getTransactionErrorByHash`, `eth_createAccessList`,
413-
`eth_estimateGasAfterCalls`, and `web3_clientVersion`.
417+
`eth_createAccessList`, and `eth_estimateGasAfterCalls`.
414418
- Not planned, because they need something the EVM-only chain does not have
415419
(Cosmos accounts, server-side keys, a mempool view, blobs, or state proofs),
416420
duplicate another method, or are development-only: `sei_getSeiAddress`,
@@ -454,11 +458,11 @@ subscription other than `newHeads`:
454458
- Blob (EIP-4844) transactions are not accepted.
455459

456460
`make autobahn-integration-test` starts a local four-validator cluster and,
457-
after a 4,000-transfer load and one contract deploy, checks every method above
458-
except the `debug_trace*` methods on all four validators, including that they
459-
return the same blocks and receipts. It traces the deploy and its block on the
460-
RPC node, which keeps the state history a past transaction replays on, and a
461-
call to the contract on every node.
461+
after a 4,000-transfer load, one contract deploy, and one failing deploy,
462+
checks every method above except the `debug_trace*` methods on all four
463+
validators, including that they return the same blocks and receipts. It traces
464+
the deploy and its block on the RPC node, which keeps the state history a past
465+
transaction replays on, and a call to the contract on every node.
462466

463467
### Request and WebSocket limits
464468

‎integration_test/autobahn/autobahn_test.go‎

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,7 @@ func testEVMOnlyLoad(t *testing.T) {
807807
contract, deploy := assertEVMOnlyContractQueries(t, rpcCtx, clients)
808808
assertEVMOnlyTraces(t, rpcCtx, clients, contract, deploy)
809809
assertEVMOnlyNewHeads(t, rpcCtx, clients)
810+
assertEVMOnlyTransactionErrors(t, rpcCtx, clients, block.Txs[0])
810811
}
811812

812813
func assertEVMOnlyBalances(t *testing.T, ctx context.Context, clients []*ethrpc.Client, txs [][]byte) {
@@ -1629,3 +1630,85 @@ func assertEVMOnlyNewHeads(t *testing.T, ctx context.Context, clients []*ethrpc.
16291630
}
16301631
}
16311632
}
1633+
1634+
// evmOnlyFailingDeployerAccount is past the contract deployer, so the failing
1635+
// deploy is the first transaction from its account.
1636+
const evmOnlyFailingDeployerAccount = 2_000_001
1637+
1638+
// assertEVMOnlyTransactionErrors sends a deploy whose init code is the INVALID
1639+
// opcode and checks, on every node, that eth_getVMError and
1640+
// eth_getTransactionErrorByHash report its error and report "" for the
1641+
// successful transfer succeeded, that an unknown hash is "" for
1642+
// eth_getTransactionErrorByHash and an error for eth_getVMError, and that
1643+
// web3_clientVersion answers in the Sei/<seid version>/ format.
1644+
func assertEVMOnlyTransactionErrors(t *testing.T, ctx context.Context, clients []*ethrpc.Client, succeeded []byte) {
1645+
t.Helper()
1646+
key, err := scenarios.DeterministicPrivateKey(evmOnlyFailingDeployerAccount)
1647+
if err != nil {
1648+
t.Fatalf("derive failing deployer key: %v", err)
1649+
}
1650+
signed, err := ethtypes.SignTx(ethtypes.NewTx(&ethtypes.LegacyTx{
1651+
GasPrice: evmOnlyTransferConfig(1).GasPrice,
1652+
Gas: evmOnlyContractGasLimit,
1653+
Data: []byte{0xfe},
1654+
}), ethtypes.LatestSignerForChainID(new(big.Int).SetUint64(tmconfig.AutobahnEVMOnlyChainID)), key)
1655+
if err != nil {
1656+
t.Fatalf("sign failing deploy: %v", err)
1657+
}
1658+
raw, err := signed.MarshalBinary()
1659+
if err != nil {
1660+
t.Fatalf("encode failing deploy: %v", err)
1661+
}
1662+
if err := clients[0].CallContext(ctx, nil, "eth_sendRawTransaction", hexutil.Bytes(raw)); err != nil {
1663+
t.Fatalf("send failing deploy: %v", err)
1664+
}
1665+
var receipt evmOnlyReceiptSummary
1666+
decodeEVMOnlyResult(t, 0, "eth_getTransactionReceipt",
1667+
waitForEVMOnlyResult(t, ctx, clients, "eth_getTransactionReceipt", signed.Hash()), &receipt)
1668+
if receipt.Status != hexutil.Uint64(ethtypes.ReceiptStatusFailed) {
1669+
t.Fatalf("failing deploy %s has status %d, want failed", signed.Hash(), receipt.Status)
1670+
}
1671+
successful := new(ethtypes.Transaction)
1672+
if err := successful.UnmarshalBinary(succeeded); err != nil {
1673+
t.Fatalf("decode successful transfer: %v", err)
1674+
}
1675+
1676+
var wantVMError string
1677+
for nodeIndex, client := range clients {
1678+
var vmError, errorByHash string
1679+
decodeEVMOnlyResult(t, nodeIndex, "eth_getVMError", evmOnlyCall(t, ctx, client, nodeIndex, "eth_getVMError", signed.Hash()), &vmError)
1680+
decodeEVMOnlyResult(t, nodeIndex, "eth_getTransactionErrorByHash",
1681+
evmOnlyCall(t, ctx, client, nodeIndex, "eth_getTransactionErrorByHash", signed.Hash()), &errorByHash)
1682+
if nodeIndex == 0 {
1683+
wantVMError = vmError
1684+
}
1685+
if vmError == "" || vmError != wantVMError || errorByHash != vmError {
1686+
t.Fatalf("node %d failing deploy: eth_getVMError = %q, eth_getTransactionErrorByHash = %q, want node 0's non-empty %q from both",
1687+
nodeIndex, vmError, errorByHash, wantVMError)
1688+
}
1689+
1690+
for _, method := range []string{"eth_getVMError", "eth_getTransactionErrorByHash"} {
1691+
var got string
1692+
decodeEVMOnlyResult(t, nodeIndex, method, evmOnlyCall(t, ctx, client, nodeIndex, method, successful.Hash()), &got)
1693+
if got != "" {
1694+
t.Fatalf("node %d %s(%s) = %q for a successful transfer, want \"\"", nodeIndex, method, successful.Hash(), got)
1695+
}
1696+
}
1697+
1698+
var unknown string
1699+
decodeEVMOnlyResult(t, nodeIndex, "eth_getTransactionErrorByHash",
1700+
evmOnlyCall(t, ctx, client, nodeIndex, "eth_getTransactionErrorByHash", common.Hash{}), &unknown)
1701+
if unknown != "" {
1702+
t.Fatalf("node %d eth_getTransactionErrorByHash for an unknown hash = %q, want \"\"", nodeIndex, unknown)
1703+
}
1704+
if err := client.CallContext(ctx, &unknown, "eth_getVMError", common.Hash{}); err == nil || !strings.Contains(err.Error(), "receipt not found") {
1705+
t.Fatalf("node %d eth_getVMError for an unknown hash = %q, %v; want the receipt-not-found error", nodeIndex, unknown, err)
1706+
}
1707+
1708+
var version string
1709+
decodeEVMOnlyResult(t, nodeIndex, "web3_clientVersion", evmOnlyCall(t, ctx, client, nodeIndex, "web3_clientVersion"), &version)
1710+
if !strings.HasPrefix(version, "Sei/") {
1711+
t.Fatalf("node %d web3_clientVersion = %q, want the Sei/<seid version>/ form", nodeIndex, version)
1712+
}
1713+
}
1714+
}

0 commit comments

Comments
 (0)