Open trajan0x opened 2 weeks ago
To handle the issue of submitting smaller transactions when over the configured cap, follow these steps:
config.go
.// Config contains configuration for the submitter.
type Config struct {
// ... existing fields
MaxTxSize int `yaml:"max_tx_size"`
}
// GetMaxTxSize returns the maximum transaction size.
func (c *Config) GetMaxTxSize(chainID int) int {
chainConfig, ok := c.Chains[chainID]
if ok && chainConfig.MaxTxSize != 0 {
return chainConfig.MaxTxSize
}
return c.MaxTxSize
}
SubmitTransaction
method in submitter.go
to check the transaction size before submission.func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID *big.Int, call ContractCallType) (nonce uint64, err error) {
// ... existing code
tx, err := call(transactor)
if err != nil {
return 0, fmt.Errorf("could not call contract: %w", err)
}
maxTxSize := t.config.GetMaxTxSize(int(chainID.Uint64()))
if len(tx.Data()) > maxTxSize {
return 0, fmt.Errorf("transaction size %d exceeds max size %d", len(tx.Data()), maxTxSize)
}
// ... existing code
}
if len(tx.Data()) > maxTxSize {
// Logic to split the transaction into smaller parts and resubmit
// This will depend on the specific contract and transaction type
}
These changes will ensure that transactions are checked for size before submission and resubmitted in smaller parts if they exceed the configured cap.
/ethergo/submitter/submitter.go /ethergo/submitter/config/config.go /ethergo/submitter /ethergo/submitter/config /ethergo/submitter/db
To address the issue of submitting smaller transactions when over the configured cap, follow these steps:
SubmitTransaction
Method in submitter.go
:
SubmitTransaction
method in ethergo/submitter/submitter.go
.func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID *big.Int, call ContractCallType) (nonce uint64, err error) {
ctx, span := t.metrics.Tracer().Start(parentCtx, "submitter.SubmitTransaction", trace.WithAttributes(
attribute.Stringer("chainID", chainID),
attribute.String("caller", runtime.FuncForPC(reflect.ValueOf(call).Pointer()).Name()),
))
defer func() {
metrics.EndSpanWithErr(span, err)
}()
// Existing code...
tx, err := call(transactor)
if err != nil {
// Check if the error is due to transaction size exceeding the cap
if isTxSizeOverCapError(err) {
// Logic to split the transaction into smaller parts and resubmit
smallerTxs, splitErr := splitTransaction(tx)
if splitErr != nil {
return 0, fmt.Errorf("could not split transaction: %w", splitErr)
}
for _, smallerTx := range smallerTxs {
_, submitErr := t.SubmitTransaction(ctx, chainID, func(opts *bind.TransactOpts) (*types.Transaction, error) {
return smallerTx, nil
})
if submitErr != nil {
return 0, fmt.Errorf("could not resubmit smaller transaction: %w", submitErr)
}
}
return 0, nil
}
return 0, fmt.Errorf("could not call contract: %w", err)
}
// Existing code...
}
func isTxSizeOverCapError(err error) bool {
// Implement logic to check if the error is due to transaction size exceeding the cap
return false // Placeholder
}
func splitTransaction(tx *types.Transaction) ([]*types.Transaction, error) {
// Implement logic to split the transaction into smaller parts
return nil, nil // Placeholder
}
config.go
:
ethergo/submitter/config/config.go
) has parameters for the transaction size cap.// Add a new field in ChainConfig struct
MaxTxSize int `yaml:"max_tx_size"`
// Add a getter method for MaxTxSize
func (c *Config) GetMaxTxSize(chainID int) int {
chainConfig, ok := c.Chains[chainID]
if ok && chainConfig.MaxTxSize != 0 {
return chainConfig.MaxTxSize
}
return c.MaxTxSize
}
submitter.go
:
func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID *big.Int, call ContractCallType) (nonce uint64, err error) {
// Existing code...
maxTxSize := t.config.GetMaxTxSize(int(chainID.Uint64()))
// Existing code...
tx, err := call(transactor)
if err != nil {
// Check if the error is due to transaction size exceeding the cap
if isTxSizeOverCapError(err) || tx.Size() > maxTxSize {
// Logic to split the transaction into smaller parts and resubmit
smallerTxs, splitErr := splitTransaction(tx)
if splitErr != nil {
return 0, fmt.Errorf("could not split transaction: %w", splitErr)
}
for _, smallerTx := range smallerTxs {
_, submitErr := t.SubmitTransaction(ctx, chainID, func(opts *bind.TransactOpts) (*types.Transaction, error) {
return smallerTx, nil
})
if submitErr != nil {
return 0, fmt.Errorf("could not resubmit smaller transaction: %w", submitErr)
}
}
return 0, nil
}
return 0, fmt.Errorf("could not call contract: %w", err)
}
// Existing code...
}
/ethergo/submitter/submitter.go /ethergo/submitter/config/config.go /ethergo/submitter
parse error and resubmit smaller attempt if over configured cap