Commit 36a43683 authored by Matthew Slipper's avatar Matthew Slipper

Code review updates

parent 6f566a47
...@@ -131,27 +131,27 @@ func (d *Driver) SubmitBatchTx( ...@@ -131,27 +131,27 @@ func (d *Driver) SubmitBatchTx(
batchTxBuildStart := time.Now() batchTxBuildStart := time.Now()
var ( var (
stateRoots [][32]byte stateRoots [][stateRootSize]byte
totalStateRootSize uint64 totalStateRootSize uint64
) )
for i := new(big.Int).Set(start); i.Cmp(end) < 0; i.Add(i, bigOne) { for i := new(big.Int).Set(start); i.Cmp(end) < 0; i.Add(i, bigOne) {
// Consume state roots until reach our maximum tx size.
if totalStateRootSize+stateRootSize > d.cfg.MaxTxSize {
break
}
block, err := d.cfg.L2Client.BlockByNumber(ctx, i) block, err := d.cfg.L2Client.BlockByNumber(ctx, i)
if err != nil { if err != nil {
return nil, err return nil, err
} }
// Consume state roots until reach our maximum tx size.
if totalStateRootSize+stateRootSize > d.cfg.MaxTxSize {
break
}
totalStateRootSize += stateRootSize totalStateRootSize += stateRootSize
stateRoots = append(stateRoots, block.Root()) stateRoots = append(stateRoots, block.Root())
} }
batchTxBuildTime := float64(time.Since(batchTxBuildStart) / time.Millisecond) batchTxBuildTime := float64(time.Since(batchTxBuildStart) / time.Millisecond)
d.metrics.BatchTxBuildTime.Set(batchTxBuildTime) d.metrics.BatchTxBuildTime.Set(batchTxBuildTime)
d.metrics.NumTxPerBatch.Observe(float64(len(stateRoots))) d.metrics.NumElementsPerBatch.Observe(float64(len(stateRoots)))
log.Info(name+" batch constructed", "num_state_roots", len(stateRoots)) log.Info(name+" batch constructed", "num_state_roots", len(stateRoots))
......
...@@ -193,20 +193,19 @@ func (d *Driver) SubmitBatchTx( ...@@ -193,20 +193,19 @@ func (d *Driver) SubmitBatchTx(
// Continue pruning until calldata size is less than configured max. // Continue pruning until calldata size is less than configured max.
if uint64(len(batchCallData)) > d.cfg.MaxTxSize { if uint64(len(batchCallData)) > d.cfg.MaxTxSize {
newBatchElementsLen := (len(batchElements) * 9) / 10 oldLen := len(batchElements)
newBatchElementsLen := (oldLen * 9) / 10
batchElements = batchElements[:newBatchElementsLen] batchElements = batchElements[:newBatchElementsLen]
log.Info("pruned batch", "old_num_txs", oldLen, "new_num_txs", newBatchElementsLen)
continue continue
} }
// Record the batch_tx_build_time. // Record the batch_tx_build_time.
batchTxBuildTime := float64(time.Since(batchTxBuildStart) / time.Millisecond) batchTxBuildTime := float64(time.Since(batchTxBuildStart) / time.Millisecond)
d.metrics.BatchTxBuildTime.Set(batchTxBuildTime) d.metrics.BatchTxBuildTime.Set(batchTxBuildTime)
d.metrics.NumTxPerBatch.Observe(float64(len(batchElements))) d.metrics.NumElementsPerBatch.Observe(float64(len(batchElements)))
log.Info(name+" batch constructed", "num_txs", len(batchElements), log.Info(name+" batch constructed", "num_txs", len(batchElements), "length", len(batchCallData))
batchTxBuildTime := float64(time.Since(batchTxBuildStart) / time.Millisecond)
d.metrics.BatchTxBuildTime.Set(batchTxBuildTime)
"length", len(batchCallData))
opts, err := bind.NewKeyedTransactorWithChainID( opts, err := bind.NewKeyedTransactorWithChainID(
d.cfg.PrivKey, d.cfg.ChainID, d.cfg.PrivKey, d.cfg.ChainID,
......
...@@ -12,9 +12,9 @@ type Metrics struct { ...@@ -12,9 +12,9 @@ type Metrics struct {
// BatchSizeInBytes tracks the size of batch submission transactions. // BatchSizeInBytes tracks the size of batch submission transactions.
BatchSizeInBytes prometheus.Histogram BatchSizeInBytes prometheus.Histogram
// NumTxPerBatch tracks the number of L2 transactions in each batch // NumElementsPerBatch tracks the number of L2 transactions in each batch
// submission. // submission.
NumTxPerBatch prometheus.Histogram NumElementsPerBatch prometheus.Histogram
// SubmissionTimestamp tracks the time at which each batch was confirmed. // SubmissionTimestamp tracks the time at which each batch was confirmed.
SubmissionTimestamp prometheus.Histogram SubmissionTimestamp prometheus.Histogram
...@@ -49,8 +49,8 @@ func NewMetrics(subsystem string) *Metrics { ...@@ -49,8 +49,8 @@ func NewMetrics(subsystem string) *Metrics {
Help: "Size of batches in bytes", Help: "Size of batches in bytes",
Subsystem: subsystem, Subsystem: subsystem,
}), }),
NumTxPerBatch: promauto.NewHistogram(prometheus.HistogramOpts{ NumElementsPerBatch: promauto.NewHistogram(prometheus.HistogramOpts{
Name: "num_txs_per_batch", Name: "num_elements_per_batch",
Help: "Number of transaction in each batch", Help: "Number of transaction in each batch",
Subsystem: subsystem, Subsystem: subsystem,
}), }),
......
...@@ -15,8 +15,8 @@ import ( ...@@ -15,8 +15,8 @@ import (
) )
var ( var (
// weiToGwei is the conversion rate from wei to gwei. // weiToEth is the conversion rate from wei to ether.
weiToGwei = new(big.Float).SetFloat64(1e-18) weiToEth = new(big.Float).SetFloat64(1e-18)
) )
// Driver is an interface for creating and submitting batch transactions for a // Driver is an interface for creating and submitting batch transactions for a
...@@ -112,7 +112,7 @@ func (s *Service) eventLoop() { ...@@ -112,7 +112,7 @@ func (s *Service) eventLoop() {
log.Error(name+" unable to get current balance", "err", err) log.Error(name+" unable to get current balance", "err", err)
continue continue
} }
s.metrics.ETHBalance.Set(weiToGwei64(balance)) s.metrics.ETHBalance.Set(weiToEth64(balance))
// Determine the range of L2 blocks that the batch submitter has not // Determine the range of L2 blocks that the batch submitter has not
// processed, and needs to take action on. // processed, and needs to take action on.
...@@ -158,6 +158,15 @@ func (s *Service) eventLoop() { ...@@ -158,6 +158,15 @@ func (s *Service) eventLoop() {
return nil, err return nil, err
} }
log.Info(
name+" submitted batch tx",
"start", start,
"end", end,
"nonce", nonce,
"tx_hash", tx.Hash(),
"gasPrice", gasPrice,
)
s.metrics.BatchSizeInBytes.Observe(float64(tx.Size())) s.metrics.BatchSizeInBytes.Observe(float64(tx.Size()))
return tx, nil return tx, nil
...@@ -191,9 +200,9 @@ func (s *Service) eventLoop() { ...@@ -191,9 +200,9 @@ func (s *Service) eventLoop() {
} }
} }
func weiToGwei64(wei *big.Int) float64 { func weiToEth64(wei *big.Int) float64 {
gwei := new(big.Float).SetInt(wei) eth := new(big.Float).SetInt(wei)
gwei.Mul(gwei, weiToGwei) eth.Mul(eth, weiToEth)
gwei64, _ := gwei.Float64() eth64, _ := eth.Float64()
return gwei64 return eth64
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment