Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
235c7af1
Unverified
Commit
235c7af1
authored
Jan 14, 2022
by
Matthew Slipper
Committed by
GitHub
Jan 14, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2008 from cfromknecht/bss-craft-then-send-tx
bss: split up SubmitBatchTx method in Driver iface
parents
e5ba9b1d
961dfe25
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
134 additions
and
45 deletions
+134
-45
driver.go
go/batch-submitter/drivers/proposer/driver.go
+61
-21
driver.go
go/batch-submitter/drivers/sequencer/driver.go
+36
-15
service.go
go/batch-submitter/service.go
+37
-9
No files found.
go/batch-submitter/drivers/proposer/driver.go
View file @
235c7af1
...
...
@@ -5,7 +5,7 @@ import (
"crypto/ecdsa"
"fmt"
"math/big"
"
time
"
"
strings
"
"github.com/ethereum-optimism/optimism/go/batch-submitter/bindings/ctc"
"github.com/ethereum-optimism/optimism/go/batch-submitter/bindings/scc"
...
...
@@ -14,6 +14,8 @@ import (
"github.com/ethereum-optimism/optimism/go/batch-submitter/txmgr"
l2ethclient
"github.com/ethereum-optimism/optimism/l2geth/ethclient"
"github.com/ethereum-optimism/optimism/l2geth/log"
"github.com/ethereum-optimism/optimism/l2geth/params"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
...
...
@@ -41,6 +43,7 @@ type Config struct {
type
Driver
struct
{
cfg
Config
sccContract
*
scc
.
StateCommitmentChain
rawSccContract
*
bind
.
BoundContract
ctcContract
*
ctc
.
CanonicalTransactionChain
walletAddr
common
.
Address
metrics
*
metrics
.
Metrics
...
...
@@ -61,11 +64,23 @@ func NewDriver(cfg Config) (*Driver, error) {
return
nil
,
err
}
parsed
,
err
:=
abi
.
JSON
(
strings
.
NewReader
(
scc
.
StateCommitmentChainABI
,
))
if
err
!=
nil
{
return
nil
,
err
}
rawSccContract
:=
bind
.
NewBoundContract
(
cfg
.
SCCAddr
,
parsed
,
cfg
.
L1Client
,
cfg
.
L1Client
,
cfg
.
L1Client
,
)
walletAddr
:=
crypto
.
PubkeyToAddress
(
cfg
.
PrivKey
.
PublicKey
)
return
&
Driver
{
cfg
:
cfg
,
sccContract
:
sccContract
,
rawSccContract
:
rawSccContract
,
ctcContract
:
ctcContract
,
walletAddr
:
walletAddr
,
metrics
:
metrics
.
NewMetrics
(
cfg
.
Name
),
...
...
@@ -136,16 +151,20 @@ func (d *Driver) GetBatchBlockRange(
return
start
,
end
,
nil
}
// SubmitBatchTx transforms the L2 blocks between start and end into a batch
// transaction using the given nonce and gasPrice. The final transaction is
// published and returned to the call.
func
(
d
*
Driver
)
SubmitBatchTx
(
// CraftBatchTx transforms the L2 blocks between start and end into a batch
// transaction using the given nonce. A dummy gas price is used in the resulting
// transaction to use for size estimation.
//
// NOTE: This method SHOULD NOT publish the resulting transaction.
func
(
d
*
Driver
)
CraftBatchTx
(
ctx
context
.
Context
,
start
,
end
,
nonce
,
gasPrice
*
big
.
Int
)
(
*
types
.
Transaction
,
error
)
{
start
,
end
,
nonce
*
big
.
Int
,
)
(
*
types
.
Transaction
,
error
)
{
name
:=
d
.
cfg
.
Name
batchTxBuildStart
:=
time
.
Now
()
log
.
Info
(
name
+
" crafting batch tx"
,
"start"
,
start
,
"end"
,
end
,
"nonce"
,
nonce
)
var
(
stateRoots
[][
stateRootSize
]
byte
...
...
@@ -166,8 +185,6 @@ func (d *Driver) SubmitBatchTx(
stateRoots
=
append
(
stateRoots
,
block
.
Root
())
}
batchTxBuildTime
:=
float64
(
time
.
Since
(
batchTxBuildStart
)
/
time
.
Millisecond
)
d
.
metrics
.
BatchTxBuildTime
.
Set
(
batchTxBuildTime
)
d
.
metrics
.
NumElementsPerBatch
.
Observe
(
float64
(
len
(
stateRoots
)))
log
.
Info
(
name
+
" batch constructed"
,
"num_state_roots"
,
len
(
stateRoots
))
...
...
@@ -178,12 +195,35 @@ func (d *Driver) SubmitBatchTx(
if
err
!=
nil
{
return
nil
,
err
}
opts
.
Nonce
=
nonce
opts
.
Context
=
ctx
opts
.
GasPrice
=
gasPrice
opts
.
Nonce
=
nonce
opts
.
GasPrice
=
big
.
NewInt
(
params
.
GWei
)
// dummy
opts
.
NoSend
=
true
blockOffset
:=
new
(
big
.
Int
)
.
SetUint64
(
d
.
cfg
.
BlockOffset
)
offsetStartsAtIndex
:=
new
(
big
.
Int
)
.
Sub
(
start
,
blockOffset
)
return
d
.
sccContract
.
AppendStateBatch
(
opts
,
stateRoots
,
offsetStartsAtIndex
)
}
// SubmitBatchTx using the passed transaction as a template, signs and publishes
// an otherwise identical transaction after setting the provided gas price. The
// final transaction is returned to the caller.
func
(
d
*
Driver
)
SubmitBatchTx
(
ctx
context
.
Context
,
tx
*
types
.
Transaction
,
gasPrice
*
big
.
Int
,
)
(
*
types
.
Transaction
,
error
)
{
opts
,
err
:=
bind
.
NewKeyedTransactorWithChainID
(
d
.
cfg
.
PrivKey
,
d
.
cfg
.
ChainID
,
)
if
err
!=
nil
{
return
nil
,
err
}
opts
.
Context
=
ctx
opts
.
Nonce
=
new
(
big
.
Int
)
.
SetUint64
(
tx
.
Nonce
())
opts
.
GasPrice
=
gasPrice
return
d
.
rawSccContract
.
RawTransact
(
opts
,
tx
.
Data
())
}
go/batch-submitter/drivers/sequencer/driver.go
View file @
235c7af1
...
...
@@ -6,13 +6,13 @@ import (
"fmt"
"math/big"
"strings"
"time"
"github.com/ethereum-optimism/optimism/go/batch-submitter/bindings/ctc"
"github.com/ethereum-optimism/optimism/go/batch-submitter/drivers"
"github.com/ethereum-optimism/optimism/go/batch-submitter/metrics"
"github.com/ethereum-optimism/optimism/go/batch-submitter/txmgr"
l2ethclient
"github.com/ethereum-optimism/optimism/l2geth/ethclient"
"github.com/ethereum-optimism/optimism/l2geth/params"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -148,19 +148,20 @@ func (d *Driver) GetBatchBlockRange(
return
start
,
end
,
nil
}
// SubmitBatchTx transforms the L2 blocks between start and end into a batch
// transaction using the given nonce and gasPrice. The final transaction is
// published and returned to the call.
func
(
d
*
Driver
)
SubmitBatchTx
(
// CraftBatchTx transforms the L2 blocks between start and end into a batch
// transaction using the given nonce. A dummy gas price is used in the resulting
// transaction to use for size estimation.
//
// NOTE: This method SHOULD NOT publish the resulting transaction.
func
(
d
*
Driver
)
CraftBatchTx
(
ctx
context
.
Context
,
start
,
end
,
nonce
,
gasPrice
*
big
.
Int
)
(
*
types
.
Transaction
,
error
)
{
start
,
end
,
nonce
*
big
.
Int
,
)
(
*
types
.
Transaction
,
error
)
{
name
:=
d
.
cfg
.
Name
log
.
Info
(
name
+
" submitting batch tx"
,
"start"
,
start
,
"end"
,
end
,
"gasPrice"
,
gasPrice
)
batchTxBuildStart
:=
time
.
Now
()
log
.
Info
(
name
+
" crafting batch tx"
,
"start"
,
start
,
"end"
,
end
,
"nonce"
,
nonce
)
var
(
batchElements
[]
BatchElement
...
...
@@ -219,9 +220,6 @@ func (d *Driver) SubmitBatchTx(
continue
}
// Record the batch_tx_build_time.
batchTxBuildTime
:=
float64
(
time
.
Since
(
batchTxBuildStart
)
/
time
.
Millisecond
)
d
.
metrics
.
BatchTxBuildTime
.
Set
(
batchTxBuildTime
)
d
.
metrics
.
NumElementsPerBatch
.
Observe
(
float64
(
len
(
batchElements
)))
d
.
metrics
.
BatchPruneCount
.
Set
(
float64
(
pruneCount
))
...
...
@@ -233,10 +231,33 @@ func (d *Driver) SubmitBatchTx(
if
err
!=
nil
{
return
nil
,
err
}
opts
.
Nonce
=
nonce
opts
.
Context
=
ctx
opts
.
GasPrice
=
gasPrice
opts
.
Nonce
=
nonce
opts
.
GasPrice
=
big
.
NewInt
(
params
.
GWei
)
// dummy
opts
.
NoSend
=
true
return
d
.
rawCtcContract
.
RawTransact
(
opts
,
batchCallData
)
}
}
// SubmitBatchTx using the passed transaction as a template, signs and publishes
// an otherwise identical transaction after setting the provided gas price. The
// final transaction is returned to the caller.
func
(
d
*
Driver
)
SubmitBatchTx
(
ctx
context
.
Context
,
tx
*
types
.
Transaction
,
gasPrice
*
big
.
Int
,
)
(
*
types
.
Transaction
,
error
)
{
opts
,
err
:=
bind
.
NewKeyedTransactorWithChainID
(
d
.
cfg
.
PrivKey
,
d
.
cfg
.
ChainID
,
)
if
err
!=
nil
{
return
nil
,
err
}
opts
.
Context
=
ctx
opts
.
Nonce
=
new
(
big
.
Int
)
.
SetUint64
(
tx
.
Nonce
())
opts
.
GasPrice
=
gasPrice
return
d
.
rawCtcContract
.
RawTransact
(
opts
,
tx
.
Data
())
}
go/batch-submitter/service.go
View file @
235c7af1
package
batchsubmitter
import
(
"bytes"
"context"
"math/big"
"sync"
...
...
@@ -43,12 +44,23 @@ type Driver interface {
// processed.
GetBatchBlockRange
(
ctx
context
.
Context
)
(
*
big
.
Int
,
*
big
.
Int
,
error
)
// SubmitBatchTx transforms the L2 blocks between start and end into a
// batch transaction using the given nonce and gasPrice. The final
// transaction is published and returned to the call.
// CraftBatchTx transforms the L2 blocks between start and end into a batch
// transaction using the given nonce. A dummy gas price is used in the
// resulting transaction to use for size estimation.
//
// NOTE: This method SHOULD NOT publish the resulting transaction.
CraftBatchTx
(
ctx
context
.
Context
,
start
,
end
,
nonce
*
big
.
Int
,
)
(
*
types
.
Transaction
,
error
)
// SubmitBatchTx using the passed transaction as a template, signs and
// publishes an otherwise identical transaction after setting the provided
// gas price. The final transaction is returned to the caller.
SubmitBatchTx
(
ctx
context
.
Context
,
start
,
end
,
nonce
,
gasPrice
*
big
.
Int
,
tx
*
types
.
Transaction
,
gasPrice
*
big
.
Int
,
)
(
*
types
.
Transaction
,
error
)
}
...
...
@@ -160,6 +172,26 @@ func (s *Service) eventLoop() {
}
nonce
:=
new
(
big
.
Int
)
.
SetUint64
(
nonce64
)
batchTxBuildStart
:=
time
.
Now
()
tx
,
err
:=
s
.
cfg
.
Driver
.
CraftBatchTx
(
s
.
ctx
,
start
,
end
,
nonce
,
)
if
err
!=
nil
{
log
.
Error
(
name
+
" unable to craft batch tx"
,
"err"
,
err
)
continue
}
batchTxBuildTime
:=
time
.
Since
(
batchTxBuildStart
)
/
time
.
Millisecond
s
.
metrics
.
BatchTxBuildTime
.
Set
(
float64
(
batchTxBuildTime
))
// Record the size of the batch transaction.
var
txBuf
bytes
.
Buffer
if
err
:=
tx
.
EncodeRLP
(
&
txBuf
);
err
!=
nil
{
log
.
Error
(
name
+
" unable to encode batch tx"
,
"err"
,
err
)
continue
}
s
.
metrics
.
BatchSizeInBytes
.
Observe
(
float64
(
len
(
txBuf
.
Bytes
())))
// Construct the transaction submission clousure that will attempt
// to send the next transaction at the given nonce and gas price.
sendTx
:=
func
(
...
...
@@ -170,9 +202,7 @@ func (s *Service) eventLoop() {
"end"
,
end
,
"nonce"
,
nonce
,
"gasPrice"
,
gasPrice
)
tx
,
err
:=
s
.
cfg
.
Driver
.
SubmitBatchTx
(
ctx
,
start
,
end
,
nonce
,
gasPrice
,
)
tx
,
err
:=
s
.
cfg
.
Driver
.
SubmitBatchTx
(
ctx
,
tx
,
gasPrice
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -186,8 +216,6 @@ func (s *Service) eventLoop() {
"gasPrice"
,
gasPrice
,
)
s
.
metrics
.
BatchSizeInBytes
.
Observe
(
float64
(
tx
.
Size
()))
return
tx
,
nil
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment