Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gas offset #623

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion claimtxman/claimtxman.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func NewClaimTxManager(ctx context.Context, cfg Config, chExitRootEvent chan *et
var monitorTx ctmtypes.TxMonitorer
if cfg.GroupingClaims.Enabled {
log.Info("ClaimTxManager working in compressor mode to group claim txs")
monitorTx = NewMonitorCompressedTxs(ctx, storage.(StorageCompressedInterface), client, cfg, nonceCache, auth, etherMan, utils.NewTimeProviderSystemLocalTime())
monitorTx = NewMonitorCompressedTxs(ctx, storage.(StorageCompressedInterface), client, cfg, nonceCache, auth, etherMan, utils.NewTimeProviderSystemLocalTime(), cfg.GroupingClaims.GasOffset)
} else {
log.Info("ClaimTxManager working in regular mode to send claim txs individually")
monitorTx = NewMonitorTxs(ctx, storage.(StorageInterface), client, cfg, nonceCache, auth)
Expand Down
9 changes: 4 additions & 5 deletions claimtxman/compose_compress_claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"math/big"
"slices"
"strings"

ctmtypes "github.com/0xPolygonHermez/zkevm-bridge-service/claimtxman/types"
"github.com/0xPolygonHermez/zkevm-bridge-service/etherman/smartcontracts/claimcompressor"
Expand Down Expand Up @@ -44,13 +43,13 @@ type bridgeClaimXParams struct {
}

type ComposeCompressClaim struct {
smcAbi abi.ABI
bridgeContractABI *abi.ABI
methodClaimAssets abi.Method
methodClaimMessages abi.Method
}

func NewComposeCompressClaim() (*ComposeCompressClaim, error) {
smcAbi, err := abi.JSON(strings.NewReader(polygonzkevmbridge.PolygonzkevmbridgeABI))
smcAbi, err := polygonzkevmbridge.PolygonzkevmbridgeMetaData.GetAbi()
if err != nil {
return nil, errors.New("fails to read abi fom Bridge contract")
}
Expand All @@ -63,7 +62,7 @@ func NewComposeCompressClaim() (*ComposeCompressClaim, error) {
return nil, errors.New("method claimMessages not found")
}
return &ComposeCompressClaim{
smcAbi: smcAbi,
bridgeContractABI: smcAbi,
methodClaimAssets: methodClaimAssets,
methodClaimMessages: methodClaimMessages,
}, nil
Expand Down Expand Up @@ -129,7 +128,7 @@ func (c *ComposeCompressClaim) extractParams(data []byte) (*bridgeClaimXParams,
}
func (c *ComposeCompressClaim) extractParamsClaimX(data []byte) (*bridgeClaimXParams, error) {
// do something
method, err := c.smcAbi.MethodById(data[:4])
method, err := c.bridgeContractABI.MethodById(data[:4])
if err != nil {
return nil, fmt.Errorf("extracting params, getting method err: %w ", err)
}
Expand Down
2 changes: 2 additions & 0 deletions claimtxman/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ type ConfigGroupingClaims struct {
RetryInterval types.Duration `mapstructure:"RetryInterval"`
// RetryTimeout is the maximum time to wait for a claim tx to be mined
RetryTimeout types.Duration `mapstructure:"RetryTimeout"`
// GasOffset is the offset for the gas estimation
GasOffset uint64 `mapstructure:"GasOffset"`
}
27 changes: 22 additions & 5 deletions claimtxman/monitor_compressed_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type StorageCompressedInterface interface {

type EthermanI interface {
CompressClaimCall(mainnetExitRoot, rollupExitRoot common.Hash, claimData []claimcompressor.ClaimCompressorCompressClaimCallData) ([]byte, error)
SendCompressedClaims(auth *bind.TransactOpts, compressedTxData []byte) (common.Hash, error)
SendCompressedClaims(auth *bind.TransactOpts, compressedTxData []byte) (*types.Transaction, error)
}
type MonitorCompressedTxs struct {
storage StorageCompressedInterface
Expand All @@ -48,6 +48,7 @@ type MonitorCompressedTxs struct {
compressClaimComposer *ComposeCompressClaim
timeProvider utils.TimeProvider
triggerGroups *GroupsTrigger
gasOffset uint64
}

func NewMonitorCompressedTxs(ctx context.Context,
Expand All @@ -57,7 +58,8 @@ func NewMonitorCompressedTxs(ctx context.Context,
nonceCache *NonceCache,
auth *bind.TransactOpts,
etherMan EthermanI,
timeProvider utils.TimeProvider) *MonitorCompressedTxs {
timeProvider utils.TimeProvider,
gasOffset uint64) *MonitorCompressedTxs {
composer, err := NewComposeCompressClaim()
if err != nil {
log.Fatal("failed to create ComposeCompressClaim: %v", err)
Expand All @@ -73,6 +75,7 @@ func NewMonitorCompressedTxs(ctx context.Context,
compressClaimComposer: composer,
timeProvider: timeProvider,
triggerGroups: NewGroupsTrigger(cfg.GroupingClaims),
gasOffset: gasOffset,
}
}

Expand Down Expand Up @@ -317,17 +320,31 @@ func (tm *MonitorCompressedTxs) SendClaims(pendingTx *PendingTxs, onlyFirstOne b
continue
}

// Estimating Gas
auth := *tm.auth
auth.NoSend = true
estimatedTx, err := tm.etherMan.SendCompressedClaims(tm.auth, group.DbEntry.CompressedTxData)
if err != nil {
msg := fmt.Sprintf("failed to call SMC SendCompressedClaims for group %d: %v", group.DbEntry.GroupID, err)
log.Warn(msg)
group.DbEntry.LastLog = msg
continue
}
auth.NoSend = false
log.Debug("GAS: ", estimatedTx.Gas())
auth.GasLimit = estimatedTx.Gas() + tm.gasOffset
log.Debug("New GAS: ", auth.GasLimit)
// Send claim tx
txHash, err := tm.etherMan.SendCompressedClaims(tm.auth, group.DbEntry.CompressedTxData)
tx, err := tm.etherMan.SendCompressedClaims(tm.auth, group.DbEntry.CompressedTxData)
if err != nil {
msg := fmt.Sprintf("failed to call SMC SendCompressedClaims for group %d: %v", group.DbEntry.GroupID, err)
log.Warn(msg)
group.DbEntry.LastLog = msg
continue
}
log.Infof("send claim tx try: %d for group_id:%d deposits_id:%s txHash:%s", group.DbEntry.NumRetries, group.DbEntry.GroupID, group.GetTxsDepositIDString(), txHash.String())
log.Infof("Send claim tx try: %d for group_id:%d deposits_id:%s txHash:%s", group.DbEntry.NumRetries, group.DbEntry.GroupID, group.GetTxsDepositIDString(), tx.Hash().String())
group.DbEntry.Status = ctmtypes.MonitoredTxGroupStatusClaiming
group.DbEntry.AddPendingTx(txHash)
group.DbEntry.AddPendingTx(tx.Hash())
group.DbEntry.NumRetries++
}
return nil
Expand Down
1 change: 1 addition & 0 deletions config/config.debug.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ AuthorizedClaimMessageAddresses = ["0x90F79bf6EB2c4f870365E785982E1f101E93b906"]
RetryInterval = "10s"
RetryTimeout = "30s"
FrequencyToProcessCompressedClaims = "1m"
GasOffset = 100000

[Etherman]
L1URL = "http://localhost:8545"
Expand Down
1 change: 1 addition & 0 deletions config/config.local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ AuthorizedClaimMessageAddresses = ["0x90F79bf6EB2c4f870365E785982E1f101E93b906"]
RetryInterval = "10s"
RetryTimeout = "30s"
FrequencyToProcessCompressedClaims = "1m"
GasOffset = 100000

[Etherman]
L1URL = "http://zkevm-mock-l1-network:8545"
Expand Down
1 change: 1 addition & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ AuthorizedClaimMessageAddresses = []
MaxRetries = 2
RetryInterval = "10s"
RetryTimeout = "30s"
GasOffset = 0


[Etherman]
Expand Down
6 changes: 3 additions & 3 deletions etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -765,13 +765,13 @@ func (etherMan *Client) AddExistingRollupEvent(ctx context.Context, vLog types.L
return nil
}

func (etherMan *Client) SendCompressedClaims(auth *bind.TransactOpts, compressedTxData []byte) (common.Hash, error) {
func (etherMan *Client) SendCompressedClaims(auth *bind.TransactOpts, compressedTxData []byte) (*types.Transaction, error) {
claimTx, err := etherMan.ClaimCompressor.SendCompressedClaims(auth, compressedTxData)
if err != nil {
log.Error("failed to call SMC SendCompressedClaims: %v", err)
return common.Hash{}, err
return nil, err
}
return claimTx.Hash(), err
return claimTx, err
}

func (etherMan *Client) CompressClaimCall(mainnetExitRoot, rollupExitRoot common.Hash, claimData []claimcompressor.ClaimCompressorCompressClaimCallData) ([]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion utils/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (c *Client) SendBridgeAsset(ctx context.Context, tokenAddr common.Address,
}
tx, err := c.Bridge.BridgeAsset(auth, destNetwork, *destAddr, amount, tokenAddr, true, metadata)
if err != nil {
log.Error("Error: ", err)
log.Error("error sending deposit. Error: ", err)
return err
}
// wait transfer to be included in a batch
Expand Down
Loading