Skip to content

Commit

Permalink
estimate gas for SubmitOriginalData (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
csdtowards authored Oct 11, 2024
1 parent e8edf9c commit aaa691e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
15 changes: 11 additions & 4 deletions disperser/batcher/transactor/transactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@ func (t *Transactor) SubmitLogEntry(daContract *contract.DAContract, dataRoots [
defer t.mu.Unlock()

// Append log on blockchain
var txHash eth_common.Hash
var tx *types.Transaction
var err error
if txHash, _, err = daContract.SubmitOriginalData(dataRoots, false); err != nil {
if tx, _, err = daContract.SubmitOriginalData(dataRoots, false, 0); err != nil {
t.logger.Debug("[transactor] estimate SubmitLogEntry tx failed")
return eth_common.Hash{}, errors.WithMessage(err, "Failed to estimate SubmitLogEntry tx")
}

gasLimit := tx.Gas() + tx.Gas()/20
if tx, _, err = daContract.SubmitOriginalData(dataRoots, false, gasLimit); err != nil {
return eth_common.Hash{}, errors.WithMessage(err, "Failed to submit log entry")
}
return txHash, nil

return tx.Hash(), nil
}

func (t *Transactor) BatchUpload(daContract *contract.DAContract, dataRoots []eth_common.Hash) (eth_common.Hash, error) {
Expand Down Expand Up @@ -67,7 +74,7 @@ func (t *Transactor) SubmitVerifiedCommitRoots(daContract *contract.DAContract,
return eth_common.Hash{}, errors.WithMessage(err, "Failed to estimate SubmitVerifiedCommitRoots")
}

gasLimit = tx.Gas()
gasLimit = tx.Gas() + tx.Gas()/20
t.logger.Info("[transactor] estimate gas", "gas limit", tx.Gas())
} else {
gasLimit = t.gasLimit
Expand Down
18 changes: 12 additions & 6 deletions disperser/contract/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,39 +115,45 @@ func (c *DAContract) SubmitVerifiedCommitRoots(submissions []da_entrance.IDAEntr
return tx, nil, nil
}

func (c *DAContract) SubmitOriginalData(dataRoots []eth_common.Hash, waitForReceipt bool) (eth_common.Hash, *types.Receipt, error) {
func (c *DAContract) SubmitOriginalData(dataRoots []eth_common.Hash, waitForReceipt bool, gasLimit uint64) (*types.Transaction, *types.Receipt, error) {
params := make([][32]byte, len(dataRoots))
for i, dataRoot := range dataRoots {
params[i] = dataRoot
}

blobPrice, err := c.BlobPrice(nil)
if err != nil {
return eth_common.Hash{}, nil, errors.WithMessage(err, "Failed to get blob price")
return nil, nil, errors.WithMessage(err, "Failed to get blob price")
}

// Submit log entry to smart contract.
opts, err := c.CreateTransactOpts()
if err != nil {
return eth_common.Hash{}, nil, errors.WithMessage(err, "Failed to create opts to send transaction")
return nil, nil, errors.WithMessage(err, "Failed to create opts to send transaction")
}

opts.Value = new(big.Int)
txValue := new(big.Int).SetUint64(uint64(len(dataRoots)))
opts.Value.Mul(blobPrice, txValue)

if gasLimit == 0 {
opts.NoSend = true
} else {
opts.GasLimit = gasLimit
}

tx, err := c.DAEntrance.SubmitOriginalData(opts, params)

if err != nil {
return eth_common.Hash{}, nil, errors.WithMessage(err, "Failed to send transaction to submit original data")
return nil, nil, errors.WithMessage(err, "Failed to send transaction to submit original data")
}

if waitForReceipt {
// Wait for successful execution
receipt, err := c.WaitForReceipt(tx.Hash(), true)
return tx.Hash(), receipt, err
return tx, receipt, err
}
return tx.Hash(), nil, nil
return tx, nil, nil
}

func (c *DAContract) CreateTransactOpts() (*bind.TransactOpts, error) {
Expand Down

0 comments on commit aaa691e

Please sign in to comment.