From 98a1ada5f6749fd10fa900700c17d52aaf93dac9 Mon Sep 17 00:00:00 2001 From: sweexordious Date: Thu, 4 Jul 2024 11:00:26 +0100 Subject: [PATCH] fix: working listener + more control --- cmd/blobstream-ops/replay/cmd.go | 9 +++-- cmd/blobstream-ops/replay/config.go | 55 +++++++++++++++++++++++++++++ cmd/blobstream-ops/verify/cmd.go | 2 +- replay/evm.go | 10 ++++-- 4 files changed, 70 insertions(+), 6 deletions(-) diff --git a/cmd/blobstream-ops/replay/cmd.go b/cmd/blobstream-ops/replay/cmd.go index 566f7fc..bc4a290 100644 --- a/cmd/blobstream-ops/replay/cmd.go +++ b/cmd/blobstream-ops/replay/cmd.go @@ -2,7 +2,6 @@ package replay import ( "context" - "fmt" "github.com/celestiaorg/blobstream-ops/cmd/blobstream-ops/common" "github.com/celestiaorg/blobstream-ops/cmd/blobstream-ops/version" @@ -114,7 +113,7 @@ func Command() *cobra.Command { defer func(trpc *http.HTTP) { err := trpc.Stop() if err != nil { - fmt.Println(err.Error()) + logger.Error("error stopping tendermint RPC", "err", err.Error()) } }(trpc) } @@ -131,6 +130,9 @@ func Command() *cobra.Command { config.TargetContractAddress, config.TargetChainGateway, config.PrivateKey, + config.HeaderRangeFunctionID, + config.NextHeaderFunctionID, + config.FilterRange, ) if err != nil { return err @@ -150,6 +152,9 @@ func Command() *cobra.Command { config.TargetContractAddress, config.TargetChainGateway, config.PrivateKey, + config.HeaderRangeFunctionID, + config.NextHeaderFunctionID, + config.FilterRange, ) }, } diff --git a/cmd/blobstream-ops/replay/config.go b/cmd/blobstream-ops/replay/config.go index dbd1b80..d200aab 100644 --- a/cmd/blobstream-ops/replay/config.go +++ b/cmd/blobstream-ops/replay/config.go @@ -2,6 +2,7 @@ package replay import ( "crypto/ecdsa" + "encoding/hex" "errors" "fmt" @@ -18,6 +19,10 @@ const ( FlagTargetEVMContractAddress = "evm.target.contract-address" FlagTargetChainGateway = "evm.target.gateway" FlagEVMPrivateKey = "evm.private-key" + FlagEVMFilterRange = "evm.filter-range" + + FlagHeaderRangeFunctionID = "circuits.header-range.functionID" + FlagNextHeaderFunctionID = "circuits.next-header.functionID" FlagVerify = "verify" @@ -50,6 +55,9 @@ func addFlags(cmd *cobra.Command) *cobra.Command { ) cmd.Flags().Bool(FlagVerify, false, "Set to verify the commitments before replaying their proofs. Require the core rpc flag to be set") cmd.Flags().String(FlagEVMPrivateKey, "", "Specify the EVM private key, in hex format without the leading 0x, to use for replaying transaction in the target chain. Corresponding account should be funded") + cmd.Flags().String(FlagHeaderRangeFunctionID, "", "Specify the function ID of the header range circuit in the target BlobstreamX contract, in hex format without the leading 0x") + cmd.Flags().String(FlagNextHeaderFunctionID, "", "Specify the function ID of the next header circuit in the target BlobstreamX contract, in hex format without the leading 0x") + cmd.Flags().Int64(FlagEVMFilterRange, 5000, "Specify the eth_getLogs filter range") return cmd } @@ -64,6 +72,9 @@ type Config struct { CoreRPC string Verify bool PrivateKey *ecdsa.PrivateKey + HeaderRangeFunctionID [32]byte + NextHeaderFunctionID [32]byte + FilterRange int64 } func (cfg Config) ValidateBasics() error { @@ -146,6 +157,46 @@ func parseFlags(cmd *cobra.Command) (Config, error) { return Config{}, fmt.Errorf("failed to hex-decode Ethereum ECDSA Private Key: %w", err) } + strHeaderRange, err := cmd.Flags().GetString(FlagHeaderRangeFunctionID) + if err != nil { + return Config{}, err + } + if strHeaderRange == "" { + return Config{}, fmt.Errorf("please set the header range function ID --%s", FlagHeaderRangeFunctionID) + } + decodedHeaderRange, err := hex.DecodeString(strHeaderRange) + if err != nil { + return Config{}, err + } + var bzHeaderRange [32]byte + copy(bzHeaderRange[:], decodedHeaderRange) + + strNextHeader, err := cmd.Flags().GetString(FlagNextHeaderFunctionID) + if err != nil { + return Config{}, err + } + if strNextHeader == "" { + return Config{}, fmt.Errorf("please set the header range function ID --%s", FlagHeaderRangeFunctionID) + } + decodedNextHeader, err := hex.DecodeString(strNextHeader) + if err != nil { + return Config{}, err + } + var bzNextHeader [32]byte + copy(bzNextHeader[:], decodedNextHeader) + + filterRange, err := cmd.Flags().GetInt64(FlagEVMFilterRange) + if err != nil { + return Config{}, err + } + + verify, err := cmd.Flags().GetBool(FlagVerify) + if err != nil { + return Config{}, err + } + + // TODO add rate limiting flag + // TODO add gas price multiplier flag return Config{ SourceEVMRPC: sourceEVMRPC, TargetEVMRPC: targetEVMRPC, @@ -156,5 +207,9 @@ func parseFlags(cmd *cobra.Command) (Config, error) { LogLevel: logLevel, LogFormat: logFormat, PrivateKey: privateKey, + NextHeaderFunctionID: bzNextHeader, + HeaderRangeFunctionID: bzHeaderRange, + FilterRange: filterRange, + Verify: verify, }, nil } diff --git a/cmd/blobstream-ops/verify/cmd.go b/cmd/blobstream-ops/verify/cmd.go index 2120ec4..5fe2c80 100644 --- a/cmd/blobstream-ops/verify/cmd.go +++ b/cmd/blobstream-ops/verify/cmd.go @@ -154,7 +154,7 @@ func VerifyContractCommand() *cobra.Command { defer func(trpc *http.HTTP) { err := trpc.Stop() if err != nil { - fmt.Println(err.Error()) + logger.Error("error stopping tendermint RPC", "err", err.Error()) } }(trpc) diff --git a/replay/evm.go b/replay/evm.go index 583919f..498afcf 100644 --- a/replay/evm.go +++ b/replay/evm.go @@ -131,9 +131,9 @@ func submitProof( logger.Info("transaction submitted", "hash", tx.Hash().Hex()) _, err = waitForTransaction(ctx, logger, client, tx, waitTimeout) if err != nil { - actualNonce, err := targetBlobstreamXContract.StateProofNonce(&bind.CallOpts{}) - if err != nil { - return err + actualNonce, err2 := targetBlobstreamXContract.StateProofNonce(&bind.CallOpts{}) + if err2 != nil { + return err2 } if actualNonce.Int64() > proofNonce { logger.Info("no need to replay this nonce, the contract has already committed to it", "nonce", actualNonce) @@ -141,6 +141,7 @@ func submitProof( } if errors.Is(err, context.DeadlineExceeded) { + logger.Debug("transaction still not included, accelerating...") // we need to speed up the transaction by increasing the gas price bigGasPrice, err := client.SuggestGasPrice(ctx) if err != nil { @@ -149,8 +150,11 @@ func submitProof( // 20% increase of the suggested gas price opts.GasPrice = big.NewInt(bigGasPrice.Int64() + bigGasPrice.Int64()/5) + logger.Debug("transaction still not included, accelerating...", "new_gas_price", opts.GasPrice.Int64()) continue } else { + logger.Error("transaction failed", "err", err.Error()) + logger.Debug("retrying...") return err } }