Skip to content

Commit

Permalink
- fix use of reflect for go 1.22 to use go 1.21 as used in the go mod
Browse files Browse the repository at this point in the history
- add tests for opt mainnet and base mainnet for before and after canyon update
- add cli generate-prestate tool to easily test firehose tracer
  • Loading branch information
Eduard-Voiculescu committed May 27, 2024
1 parent f5fa975 commit e45ed70
Show file tree
Hide file tree
Showing 14 changed files with 2,507 additions and 149 deletions.
2 changes: 1 addition & 1 deletion eth/tracers/firehose.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ func (f *Firehose) OnTxEnd(receipt *types.Receipt, err error) {

trxTrace := f.completeTransaction(receipt)

if receipt.DepositReceiptVersion != nil {
if receipt.DepositNonce != nil && trxTrace.Type == types.DepositTxType {
trxTrace.Nonce = *receipt.DepositNonce
}

Expand Down
4 changes: 2 additions & 2 deletions eth/tracers/firehose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ var pbFieldNameToGethMapping = map[string]string{
}

var (
pbHeaderType = reflect.TypeFor[pbeth.BlockHeader]()
gethHeaderType = reflect.TypeFor[types.Header]()
pbHeaderType = reflect.TypeOf((*pbeth.BlockHeader)(nil)).Elem()
gethHeaderType = reflect.TypeOf((*types.Header)(nil)).Elem()
)

func Test_TypesHeader_AllConsensusFieldsAreKnown(t *testing.T) {
Expand Down
5 changes: 4 additions & 1 deletion eth/tracers/internal/tracetest/firehose/firehose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ func TestFirehosePrestate(t *testing.T) {
testFolders := []string{
"./testdata/TestFirehosePrestate/keccak256_too_few_memory_bytes_get_padded",
"./testdata/TestFirehosePrestate/failed_deposit",
"./testdata/TestFirehosePrestate/deposit_nonce_check",
"./testdata/TestFirehosePrestate/deposit_nonce_check_optimism_before_canyon",
"./testdata/TestFirehosePrestate/deposit_nonce_check_optimism_after_canyon",
"./testdata/TestFirehosePrestate/deposit_nonce_check_base_before_canyon",
"./testdata/TestFirehosePrestate/deposit_nonce_check_base_after_canyon",
}

for _, folder := range testFolders {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generate prestate

To test out the various changes to the firehose tracer, you can run the `generate-prestate` subcommend here. Currently, only op stack blockchains are supported.

```bash
export ARCHIVE_ENDPOINT="rpc_archive_node_endpoint"

# generate-prestate <network (optMainnet or baseMainnet)> <transaction_id>
# the below example run was used to create the prestate.json file for the deposit_nonce_check_optimism_after_canyon test
go run ./generate-prestate optMainnet 0xb77e56d591aab27502548d4d85aff6c1f835c1e4e820b2360751209516a63472 > testdata/TestFirehosePrestate/deposit_nonce_check_optimism_after_canyon/prestate.json
```

Then modify the method `TestFirehosePrestate` in `firehose_test.go` and add the new test

```bash
# the below command will create a file such as block.{blockNumber}.golden.json
# validation needs to be done between the created file and an RPC endpoint to make sure the files are on par
GOLDEN_UPDATE=true go test ./... -run "TestFirehosePrestate/deposit_nonce_check_optimism_after_canyon"
```
44 changes: 32 additions & 12 deletions eth/tracers/internal/tracetest/firehose/generate-prestate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,49 @@ import (
"golang.org/x/exp/maps"
)

// Currently only supports op-based blockchains
var configByName = map[string]*params.ChainConfig{
"mainnet": params.MainnetChainConfig,
"goerli": params.GoerliChainConfig,
"sepolia": params.SepoliaChainConfig,
"holesky": params.HoleskyChainConfig,
"optMainnet": nil,
"optMainnet": nil,
"baseMainnet": nil,
}

// Currently only supports op-based blockchains
var networkToChainID = map[string]uint64{
"optMainnet": params.OPMainnetChainID,
"baseMainnet": params.BaseMainnetChainID,
}

func main() {
optMainnetConfig, err := params.LoadOPStackChainConfig(params.OPMainnetChainID)
noError(err, "Failed to load OPStack mainnet chain config")
configByName["optMainnet"] = optMainnetConfig
args := os.Args

if len(args) < 2 {
fmt.Println("Usage: generate-prestate <network> <tx-hash>")
return
}

networkArg := args[1]
netorkChainId, ok := networkToChainID[networkArg]
if !ok {
fmt.Printf("Unknown network %q, valid networks are %q\n", networkArg, strings.Join(maps.Keys(configByName), ", "))
return
}
txHashArg := args[2]
log("network chain ID", netorkChainId)

mainnetConfig, err := params.LoadOPStackChainConfig(netorkChainId)
noError(err, "Failed to load mainnet chain config")
configByName[networkArg] = mainnetConfig

ensure(len(os.Args) == 3, "Usage: generate-prestate <network> <tx-hash>")

config, found := configByName[os.Args[1]]
ensure(found, "Unknown network %q, valid networks are %q", os.Args[1], strings.Join(maps.Keys(configByName), ", "))
config, found := configByName[networkArg]
ensure(found, "Unknown network %q, valid networks are %q", networkArg, strings.Join(maps.Keys(configByName), ", "))

endpoint := os.Getenv("ARCHIVE_ENDPOINT")
ensure(endpoint != "", "ARCHIVE_ENDPOINT environment variable is not set")

txHash := common.HexToHash(os.Args[2])
ensure(txHash.Big().Sign() != 0, "Argument %q is not a valid transaction hash", os.Args[1])
txHash := common.HexToHash(txHashArg)
ensure(txHash.Big().Sign() != 0, "Argument %q is not a valid transaction hash", networkArg)

client, err := rpc.DialOptions(context.Background(), endpoint)
noError(err, "Failed to connect to RPC server")
Expand Down

This file was deleted.

Loading

0 comments on commit e45ed70

Please sign in to comment.