diff --git a/ethtxmanager/config.go b/ethtxmanager/config.go index 1bd4897..e2902e7 100644 --- a/ethtxmanager/config.go +++ b/ethtxmanager/config.go @@ -66,4 +66,14 @@ type Config struct { // Log configuration Log log.Config `mapstructure:"Log"` + + // SafeStatusL1NumberOfBlocks overwrites the number of blocks to consider a tx as safe + // overwriting the default value provided by the network + // 0 means that the default value will be used + SafeStatusL1NumberOfBlocks uint64 `mapstructure:"SafeStatusL1NumberOfBlocks"` + + // FinalizedStatusL1NumberOfBlocks overwrites the number of blocks to consider a tx as finalized + // overwriting the default value provided by the network + // 0 means that the default value will be used + FinalizedStatusL1NumberOfBlocks uint64 `mapstructure:"FinalizedStatusL1NumberOfBlocks"` } diff --git a/ethtxmanager/ethtxmanager.go b/ethtxmanager/ethtxmanager.go index 0a9d534..f6f6715 100644 --- a/ethtxmanager/ethtxmanager.go +++ b/ethtxmanager/ethtxmanager.go @@ -497,11 +497,22 @@ func (c *Client) waitMinedTxToBeSafe(ctx context.Context) error { log.Debugf("found %v mined monitored tx to process", len(mTxs)) - // Get Safe block Number - safeL1BlockNumberFetch := l1_check_block.NewSafeL1BlockNumberFetch(l1_check_block.SafeBlockNumber, 0) - safeBlockNumber, err := safeL1BlockNumberFetch.GetSafeBlockNumber(ctx, c.etherman) - if err != nil { - return fmt.Errorf("failed to get safe block number: %v", err) + safeBlockNumber := uint64(0) + if c.cfg.SafeStatusL1NumberOfBlocks > 0 { + // Overwrite the number of blocks to consider a tx as safe + currentBlockNumber, err := c.etherman.GetLatestBlockNumber(ctx) + if err != nil { + return fmt.Errorf("failed to get latest block number: %v", err) + } + + safeBlockNumber = currentBlockNumber - c.cfg.SafeStatusL1NumberOfBlocks + } else { + // Get Safe block Number + safeL1BlockNumberFetch := l1_check_block.NewSafeL1BlockNumberFetch(l1_check_block.SafeBlockNumber, 0) + safeBlockNumber, err = safeL1BlockNumberFetch.GetSafeBlockNumber(ctx, c.etherman) + if err != nil { + return fmt.Errorf("failed to get safe block number: %v", err) + } } for _, mTx := range mTxs { @@ -530,11 +541,22 @@ func (c *Client) waitSafeTxToBeFinalized(ctx context.Context) error { log.Debugf("found %v safe monitored tx to process", len(mTxs)) - // Get Finalized block Number - safeL1BlockNumberFetch := l1_check_block.NewSafeL1BlockNumberFetch(l1_check_block.FinalizedBlockNumber, 0) - finaLizedBlockNumber, err := safeL1BlockNumberFetch.GetSafeBlockNumber(ctx, c.etherman) - if err != nil { - return fmt.Errorf("failed to get finalized block number: %v", err) + finaLizedBlockNumber := uint64(0) + if c.cfg.SafeStatusL1NumberOfBlocks > 0 { + // Overwrite the number of blocks to consider a tx as finalized + currentBlockNumber, err := c.etherman.GetLatestBlockNumber(ctx) + if err != nil { + return fmt.Errorf("failed to get latest block number: %v", err) + } + + finaLizedBlockNumber = currentBlockNumber - c.cfg.FinalizedStatusL1NumberOfBlocks + } else { + // Get Network Default value + safeL1BlockNumberFetch := l1_check_block.NewSafeL1BlockNumberFetch(l1_check_block.FinalizedBlockNumber, 0) + finaLizedBlockNumber, err = safeL1BlockNumberFetch.GetSafeBlockNumber(ctx, c.etherman) + if err != nil { + return fmt.Errorf("failed to get finalized block number: %v", err) + } } for _, mTx := range mTxs { diff --git a/test/main.go b/test/main.go index 7805c18..506bdd1 100644 --- a/test/main.go +++ b/test/main.go @@ -21,17 +21,19 @@ var ( func main() { config := ethtxmanager.Config{ - FrequencyToMonitorTxs: types.Duration{Duration: 1 * time.Second}, - WaitTxToBeMined: types.Duration{Duration: 2 * time.Minute}, - GetReceiptMaxTime: types.Duration{Duration: 10 * time.Second}, - GetReceiptWaitInterval: types.Duration{Duration: 250 * time.Millisecond}, - ForcedGas: 0, - GasPriceMarginFactor: 1, - MaxGasPriceLimit: 0, - PersistenceFilename: "ethtxmanager-persistence.json", - ReadPendingL1Txs: false, - Log: log.Config{Level: "info", Environment: "development", Outputs: []string{"stderr"}}, - PrivateKeys: []types.KeystoreFileConfig{{Path: "test.keystore", Password: "testonly"}}, + FrequencyToMonitorTxs: types.Duration{Duration: 1 * time.Second}, + WaitTxToBeMined: types.Duration{Duration: 2 * time.Minute}, + GetReceiptMaxTime: types.Duration{Duration: 10 * time.Second}, + GetReceiptWaitInterval: types.Duration{Duration: 250 * time.Millisecond}, + ForcedGas: 0, + GasPriceMarginFactor: 1, + MaxGasPriceLimit: 0, + SafeStatusL1NumberOfBlocks: 0, + FinalizedStatusL1NumberOfBlocks: 0, + PersistenceFilename: "ethtxmanager-persistence.json", + ReadPendingL1Txs: false, + Log: log.Config{Level: "info", Environment: "development", Outputs: []string{"stderr"}}, + PrivateKeys: []types.KeystoreFileConfig{{Path: "test.keystore", Password: "testonly"}}, Etherman: etherman.Config{ URL: "http://localhost:8545", HTTPHeaders: map[string]string{},