Skip to content

Commit

Permalink
fix: working listener + more control
Browse files Browse the repository at this point in the history
  • Loading branch information
rach-id committed Jul 4, 2024
1 parent 3414640 commit 98a1ada
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 6 deletions.
9 changes: 7 additions & 2 deletions cmd/blobstream-ops/replay/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand All @@ -131,6 +130,9 @@ func Command() *cobra.Command {
config.TargetContractAddress,
config.TargetChainGateway,
config.PrivateKey,
config.HeaderRangeFunctionID,

Check failure on line 133 in cmd/blobstream-ops/replay/cmd.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

too many arguments in call to replay.Catchup

Check failure on line 133 in cmd/blobstream-ops/replay/cmd.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

too many arguments in call to replay.Catchup

Check failure on line 133 in cmd/blobstream-ops/replay/cmd.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

too many arguments in call to replay.Catchup

Check failure on line 133 in cmd/blobstream-ops/replay/cmd.go

View workflow job for this annotation

GitHub Actions / test / test

too many arguments in call to replay.Catchup

Check failure on line 133 in cmd/blobstream-ops/replay/cmd.go

View workflow job for this annotation

GitHub Actions / test / test-coverage

too many arguments in call to replay.Catchup

Check failure on line 133 in cmd/blobstream-ops/replay/cmd.go

View workflow job for this annotation

GitHub Actions / test / test-race

too many arguments in call to replay.Catchup
config.NextHeaderFunctionID,
config.FilterRange,
)
if err != nil {
return err
Expand All @@ -150,6 +152,9 @@ func Command() *cobra.Command {
config.TargetContractAddress,
config.TargetChainGateway,
config.PrivateKey,
config.HeaderRangeFunctionID,

Check failure on line 155 in cmd/blobstream-ops/replay/cmd.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

too many arguments in call to replay.Follow

Check failure on line 155 in cmd/blobstream-ops/replay/cmd.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

too many arguments in call to replay.Follow

Check failure on line 155 in cmd/blobstream-ops/replay/cmd.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

too many arguments in call to replay.Follow

Check failure on line 155 in cmd/blobstream-ops/replay/cmd.go

View workflow job for this annotation

GitHub Actions / test / test

too many arguments in call to replay.Follow

Check failure on line 155 in cmd/blobstream-ops/replay/cmd.go

View workflow job for this annotation

GitHub Actions / test / test-coverage

too many arguments in call to replay.Follow

Check failure on line 155 in cmd/blobstream-ops/replay/cmd.go

View workflow job for this annotation

GitHub Actions / test / test-race

too many arguments in call to replay.Follow
config.NextHeaderFunctionID,
config.FilterRange,
)
},
}
Expand Down
55 changes: 55 additions & 0 deletions cmd/blobstream-ops/replay/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package replay

import (
"crypto/ecdsa"
"encoding/hex"
"errors"
"fmt"

Expand All @@ -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"

Expand Down Expand Up @@ -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
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion cmd/blobstream-ops/verify/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 7 additions & 3 deletions replay/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,17 @@ 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)
return nil
}

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 {
Expand All @@ -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 {

Check failure on line 155 in replay/evm.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (revive)
logger.Error("transaction failed", "err", err.Error())
logger.Debug("retrying...")
return err
}
}
Expand Down

0 comments on commit 98a1ada

Please sign in to comment.