Skip to content

Commit

Permalink
Merge pull request #195 from covalenthq/develop
Browse files Browse the repository at this point in the history
Bsp-agent-DTM-RC:v1.4.7
  • Loading branch information
rogarcia authored Apr 28, 2023
2 parents 63fb420 + fc3a2c2 commit 7e0aa67
Show file tree
Hide file tree
Showing 8 changed files with 1,261 additions and 964 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/covalenthq/bsp-agent
go 1.19

require (
cloud.google.com/go/storage v1.30.0
cloud.google.com/go/storage v1.30.1
github.com/TylerBrock/colorjson v0.0.0-20200706003622-8a50f05110d2
github.com/banzaicloud/logrus-runtime-formatter v0.0.0-20190729070250-5ae5475bae5e
github.com/btcsuite/btcd v0.22.0-beta // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2Aawl
cloud.google.com/go/iam v0.13.0 h1:+CmB+K0J/33d0zSQ9SlFWUeCCEn5XJA0ZMZ3pHE9u8k=
cloud.google.com/go/iam v0.13.0/go.mod h1:ljOg+rcNfzZ5d6f1nAUJ8ZIxOaZUVoS14bKCtaLZ/D0=
cloud.google.com/go/longrunning v0.4.1 h1:v+yFJOfKC3yZdY6ZUI933pIYdhyhV8S3NpWrXWmg7jM=
cloud.google.com/go/storage v1.30.0 h1:g1yrbxAWOrvg/594228pETWkOi00MLTrOWfh56veU5o=
cloud.google.com/go/storage v1.30.0/go.mod h1:xAVretHSROm1BQX4IIsoVgJqw0LqOyX+I/O2GzRAzdE=
cloud.google.com/go/storage v1.30.1 h1:uOdMxAs8HExqBlnLtnQyP0YkvbiDpdGShGKtx6U/oNM=
cloud.google.com/go/storage v1.30.1/go.mod h1:NfxhC0UJE1aXSx7CIIbCf7y9HKT7BiccwkR7+P7gN8E=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20201218220906-28db891af037/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
gioui.org v0.0.0-20210308172011-57750fc8a0a6/go.mod h1:RSH6KIUZ0p2xy5zHDxgAM4zumjgTw83q2ge/PI+yyw8=
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

var (
blockDivisorDefault = 3
consumerPendingTimeoutDefault = 60
consumerPendingTimeoutDefault = 180
logFolderDefault = "./logs/"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/node/eth_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

const (
consumerEvents int64 = 1
consumerPendingIdleTime int64 = 30
consumerPendingIdleTime int64 = 360
consumerPendingTimeTicker int64 = 10
start string = ">"
segmentLength int = 1
Expand Down
46 changes: 40 additions & 6 deletions internal/proof/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"crypto/sha256"
"encoding/json"
"math/big"
"strings"
"time"

Expand All @@ -19,8 +20,10 @@ import (
)

const (
proofTxTimeout uint64 = 301
retryCountLimit int = 1 // 1 retry for proofchain submission
proofTxTimeout uint64 = 480
retryCountLimit int = 1 // 1 retry for proofchain submission
basefeeWiggleMultiplier = 2
moonbeamStaticBaseFee int64 = 100000000000 // moonbeam static base fee, to be removed after RT2300
)

// ProofchainInteractor a wrapper over proofchain contract to help clients interact with it
Expand Down Expand Up @@ -66,11 +69,41 @@ func (interactor *ProofchainInteractor) SendBlockReplicaProofTx(ctx context.Cont
}
sha256Result := sha256.Sum256(jsonResult)

executeWithRetry(ctx, interactor.proofChainContract, interactor.ethClient, opts, blockReplica, txHash, chainHeight, replicaURL, sha256Result, 0)
executeWithRetry(ctx, interactor, interactor.proofChainContract, interactor.ethClient, opts, blockReplica, txHash, chainHeight, replicaURL, sha256Result, 0)
}

func executeWithRetry(ctx context.Context, proofChainContract *ProofChain, ethClient *ethclient.Client, opts *bind.TransactOpts, blockReplica *ty.BlockReplica, txHash chan string, chainHeight uint64, replicaURL string, sha256Result [sha256.Size]byte, retryCount int) {
transaction, err := proofChainContract.SubmitBlockSpecimenProof(opts, blockReplica.NetworkId, chainHeight, blockReplica.Hash, sha256Result, replicaURL)
func (interactor *ProofchainInteractor) setTransactionFeeParams(ctx context.Context, opts *bind.TransactOpts) (returnOpts *bind.TransactOpts) {
baseFee := moonbeamStaticBaseFee

switch head, errHead := interactor.ethClient.HeaderByNumber(ctx, nil); {
case errHead != nil:
log.Error("cannot find the latest header: ", errHead.Error())
case head.BaseFee != nil:
baseFee = head.BaseFee.Int64()
default:
log.Info("base fee not found in latest header, using static fee for moonbeam")
}

gasTipCap, err := interactor.ethClient.SuggestGasTipCap(ctx)
if err != nil {
log.Error("cannot get the gas tip cap, will revert to legacy tx: ", err.Error())
}
gasFeeCap := new(big.Int).Add(
gasTipCap,
new(big.Int).Mul(big.NewInt(baseFee), big.NewInt(basefeeWiggleMultiplier)),
)

opts.GasTipCap = gasTipCap
opts.GasFeeCap = gasFeeCap
log.Info("tip cap: ", gasTipCap, " fee cap: ", gasFeeCap)

return opts
}

func executeWithRetry(ctx context.Context, interactor *ProofchainInteractor, proofChainContract *ProofChain, ethClient *ethclient.Client, opts *bind.TransactOpts, blockReplica *ty.BlockReplica, txHash chan string, chainHeight uint64, replicaURL string, sha256Result [sha256.Size]byte, retryCount int) {
feeOpts := interactor.setTransactionFeeParams(ctx, opts)

transaction, err := proofChainContract.SubmitBlockSpecimenProof(feeOpts, blockReplica.NetworkId, chainHeight, blockReplica.Hash, sha256Result, replicaURL)

if err != nil {
if strings.Contains(err.Error(), "Session submissions have closed") {
Expand Down Expand Up @@ -126,7 +159,8 @@ func executeWithRetry(ctx context.Context, proofChainContract *ProofChain, ethCl
return
}
log.Error("proof tx failed/reverted, retrying proof tx for block hash: ", blockReplica.Hash.String())
executeWithRetry(ctx, proofChainContract, ethClient, opts, blockReplica, txHash, chainHeight, replicaURL, sha256Result, retryCount+1)
newFeeOpts := interactor.setTransactionFeeParams(ctx, opts)
executeWithRetry(ctx, interactor, proofChainContract, ethClient, newFeeOpts, blockReplica, txHash, chainHeight, replicaURL, sha256Result, retryCount+1)

return
}
Expand Down
Loading

0 comments on commit 7e0aa67

Please sign in to comment.