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

Code review updates

parent 6f566a47
......@@ -131,27 +131,27 @@ func (d *Driver) SubmitBatchTx(
batchTxBuildStart := time.Now()
var (
stateRoots [][32]byte
stateRoots [][stateRootSize]byte
totalStateRootSize uint64
)
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)
if err != nil {
return nil, err
}
// Consume state roots until reach our maximum tx size.
if totalStateRootSize+stateRootSize > d.cfg.MaxTxSize {
break
}
totalStateRootSize += stateRootSize
stateRoots = append(stateRoots, block.Root())
}
batchTxBuildTime := float64(time.Since(batchTxBuildStart) / time.Millisecond)
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))
......
......@@ -193,20 +193,19 @@ func (d *Driver) SubmitBatchTx(
// Continue pruning until calldata size is less than configured max.
if uint64(len(batchCallData)) > d.cfg.MaxTxSize {
newBatchElementsLen := (len(batchElements) * 9) / 10
oldLen := len(batchElements)
newBatchElementsLen := (oldLen * 9) / 10
batchElements = batchElements[:newBatchElementsLen]
log.Info("pruned batch", "old_num_txs", oldLen, "new_num_txs", newBatchElementsLen)
continue
}
// Record the batch_tx_build_time.
batchTxBuildTime := float64(time.Since(batchTxBuildStart) / time.Millisecond)
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),
batchTxBuildTime := float64(time.Since(batchTxBuildStart) / time.Millisecond)
d.metrics.BatchTxBuildTime.Set(batchTxBuildTime)
"length", len(batchCallData))
log.Info(name+" batch constructed", "num_txs", len(batchElements), "length", len(batchCallData))
opts, err := bind.NewKeyedTransactorWithChainID(
d.cfg.PrivKey, d.cfg.ChainID,
......
......@@ -12,9 +12,9 @@ type Metrics struct {
// BatchSizeInBytes tracks the size of batch submission transactions.
BatchSizeInBytes prometheus.Histogram
// NumTxPerBatch tracks the number of L2 transactions in each batch
// NumElementsPerBatch tracks the number of L2 transactions in each batch
// submission.
NumTxPerBatch prometheus.Histogram
NumElementsPerBatch prometheus.Histogram
// SubmissionTimestamp tracks the time at which each batch was confirmed.
SubmissionTimestamp prometheus.Histogram
......@@ -49,8 +49,8 @@ func NewMetrics(subsystem string) *Metrics {
Help: "Size of batches in bytes",
Subsystem: subsystem,
}),
NumTxPerBatch: promauto.NewHistogram(prometheus.HistogramOpts{
Name: "num_txs_per_batch",
NumElementsPerBatch: promauto.NewHistogram(prometheus.HistogramOpts{
Name: "num_elements_per_batch",
Help: "Number of transaction in each batch",
Subsystem: subsystem,
}),
......
......@@ -15,8 +15,8 @@ import (
)
var (
// weiToGwei is the conversion rate from wei to gwei.
weiToGwei = new(big.Float).SetFloat64(1e-18)
// weiToEth is the conversion rate from wei to ether.
weiToEth = new(big.Float).SetFloat64(1e-18)
)
// Driver is an interface for creating and submitting batch transactions for a
......@@ -112,7 +112,7 @@ func (s *Service) eventLoop() {
log.Error(name+" unable to get current balance", "err", err)
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
// processed, and needs to take action on.
......@@ -158,6 +158,15 @@ func (s *Service) eventLoop() {
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()))
return tx, nil
......@@ -191,9 +200,9 @@ func (s *Service) eventLoop() {
}
}
func weiToGwei64(wei *big.Int) float64 {
gwei := new(big.Float).SetInt(wei)
gwei.Mul(gwei, weiToGwei)
gwei64, _ := gwei.Float64()
return gwei64
func weiToEth64(wei *big.Int) float64 {
eth := new(big.Float).SetInt(wei)
eth.Mul(eth, weiToEth)
eth64, _ := eth.Float64()
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