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
2e00002a
Unverified
Commit
2e00002a
authored
Aug 20, 2021
by
Kelvin Fichter
Committed by
Kelvin Fichter
Nov 10, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: update OVM_ETH usage
parent
3605b963
Changes
20
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
210 additions
and
149 deletions
+210
-149
fee-payment.spec.ts
integration-tests/test/fee-payment.spec.ts
+1
-2
native-eth-ovm-calls.spec.ts
integration-tests/test/native-eth-ovm-calls.spec.ts
+2
-3
native-eth.spec.ts
integration-tests/test/native-eth.spec.ts
+9
-18
rpc.spec.ts
integration-tests/test/rpc.spec.ts
+4
-8
env.ts
integration-tests/test/shared/env.ts
+1
-2
stress-tests.spec.ts
integration-tests/test/stress-tests.spec.ts
+2
-4
bind_test.go
l2geth/accounts/abi/bind/bind_test.go
+65
-63
keystore.go
l2geth/accounts/keystore/keystore.go
+2
-2
clique.go
l2geth/consensus/clique/clique.go
+8
-5
evm.go
l2geth/core/evm.go
+2
-1
genesis.go
l2geth/core/genesis.go
+5
-4
statedb.go
l2geth/core/state/statedb.go
+63
-13
state_processor.go
l2geth/core/state_processor.go
+2
-1
state_transition.go
l2geth/core/state_transition.go
+3
-4
tx_pool.go
l2geth/core/tx_pool.go
+2
-2
api_backend.go
l2geth/eth/api_backend.go
+8
-1
backend.go
l2geth/eth/backend.go
+5
-5
api.go
l2geth/internal/ethapi/api.go
+7
-11
constants.go
l2geth/rollup/dump/constants.go
+7
-0
config.go
l2geth/rollup/rcfg/config.go
+12
-0
No files found.
integration-tests/test/fee-payment.spec.ts
View file @
2e00002a
...
...
@@ -12,8 +12,7 @@ import { IS_LIVE_NETWORK } from './shared/utils'
import
{
OptimismEnv
}
from
'
./shared/env
'
import
{
Direction
}
from
'
./shared/watcher-utils
'
// SKIP: ETH value PR
describe
.
skip
(
'
Fee Payment Integration Tests
'
,
async
()
=>
{
describe
(
'
Fee Payment Integration Tests
'
,
async
()
=>
{
let
env
:
OptimismEnv
before
(
async
()
=>
{
env
=
await
OptimismEnv
.
new
()
...
...
integration-tests/test/native-eth-ovm-calls.spec.ts
View file @
2e00002a
...
...
@@ -13,8 +13,7 @@ import { Interface } from 'ethers/lib/utils'
chai
.
use
(
solidity
)
// SKIP: ETH value PR
describe
.
skip
(
'
Native ETH value integration tests
'
,
()
=>
{
describe
(
'
Native ETH value integration tests
'
,
()
=>
{
let
env
:
OptimismEnv
let
wallet
:
Wallet
let
other
:
Wallet
...
...
@@ -332,7 +331,7 @@ describe.skip('Native ETH value integration tests', () => {
// Grab public variable from the EM
const
OVM_ExecutionManager
=
new
Contract
(
await
env
.
addressManager
.
getAddress
(
'
OVM_ExecutionManager
'
),
getContractInterface
(
'
OVM_ExecutionManager
'
,
false
),
getContractInterface
(
'
OVM_ExecutionManager
'
),
env
.
l1Wallet
.
provider
)
const
CALL_WITH_VALUE_INTRINSIC_GAS_BIGNUM
=
...
...
integration-tests/test/native-eth.spec.ts
View file @
2e00002a
...
...
@@ -19,8 +19,7 @@ const DEFAULT_TEST_GAS_L2 = 1_300_000
// TX size enforced by CTC:
const
MAX_ROLLUP_TX_SIZE
=
50
_000
// SKIP: ETH value PR
describe
.
skip
(
'
Native ETH Integration Tests
'
,
async
()
=>
{
describe
(
'
Native ETH Integration Tests
'
,
async
()
=>
{
let
env
:
OptimismEnv
let
l1Bob
:
Wallet
let
l2Bob
:
Wallet
...
...
@@ -345,21 +344,14 @@ describe.skip('Native ETH Integration Tests', async () => {
expect
(
await
env
.
l2Wallet
.
provider
.
getBalance
(
env
.
l2Wallet
.
address
)
).
to
.
equal
(
initialBalance
)
expect
(
receipt
.
events
.
length
).
to
.
equal
(
4
)
// The first transfer event is fee payment
const
[,
firstTransferEvent
,
secondTransferEvent
,
depositEvent
]
=
receipt
.
events
expect
(
receipt
.
events
.
length
).
to
.
equal
(
2
)
expect
(
firstTransferEvent
.
event
).
to
.
equal
(
'
Transfer
'
)
expect
(
firstTransferEvent
.
args
.
from
).
to
.
equal
(
env
.
l2Wallet
.
address
)
expect
(
firstTransferEvent
.
args
.
to
).
to
.
equal
(
env
.
ovmEth
.
address
)
expect
(
firstTransferEvent
.
args
.
value
).
to
.
equal
(
value
)
const
[
transferEvent
,
depositEvent
]
=
receipt
.
events
expect
(
secondT
ransferEvent
.
event
).
to
.
equal
(
'
Transfer
'
)
expect
(
secondT
ransferEvent
.
args
.
from
).
to
.
equal
(
env
.
ovmEth
.
address
)
expect
(
secondT
ransferEvent
.
args
.
to
).
to
.
equal
(
env
.
l2Wallet
.
address
)
expect
(
secondT
ransferEvent
.
args
.
value
).
to
.
equal
(
value
)
expect
(
t
ransferEvent
.
event
).
to
.
equal
(
'
Transfer
'
)
expect
(
t
ransferEvent
.
args
.
from
).
to
.
equal
(
env
.
ovmEth
.
address
)
expect
(
t
ransferEvent
.
args
.
to
).
to
.
equal
(
env
.
l2Wallet
.
address
)
expect
(
t
ransferEvent
.
args
.
value
).
to
.
equal
(
value
)
expect
(
depositEvent
.
event
).
to
.
equal
(
'
Deposit
'
)
expect
(
depositEvent
.
args
.
dst
).
to
.
equal
(
env
.
l2Wallet
.
address
)
...
...
@@ -385,10 +377,9 @@ describe.skip('Native ETH Integration Tests', async () => {
expect
(
await
env
.
l2Wallet
.
provider
.
getBalance
(
env
.
l2Wallet
.
address
)
).
to
.
equal
(
initialBalance
)
expect
(
receipt
.
events
.
length
).
to
.
equal
(
2
)
expect
(
receipt
.
events
.
length
).
to
.
equal
(
1
)
// The first transfer event is fee payment
const
depositEvent
=
receipt
.
events
[
1
]
const
depositEvent
=
receipt
.
events
[
0
]
expect
(
depositEvent
.
event
).
to
.
equal
(
'
Withdrawal
'
)
expect
(
depositEvent
.
args
.
src
).
to
.
equal
(
env
.
l2Wallet
.
address
)
expect
(
depositEvent
.
args
.
wad
).
to
.
equal
(
value
)
...
...
integration-tests/test/rpc.spec.ts
View file @
2e00002a
...
...
@@ -94,8 +94,7 @@ describe('Basic RPC tests', () => {
).
to
.
be
.
rejectedWith
(
'
Cannot submit unprotected transaction
'
)
})
// SKIP: needs ETH value PR
it
.
skip
(
'
should accept a transaction with a value
'
,
async
()
=>
{
it
(
'
should accept a transaction with a value
'
,
async
()
=>
{
const
tx
=
{
...
DEFAULT_TRANSACTION
,
chainId
:
await
env
.
l2Wallet
.
getChainId
(),
...
...
@@ -113,8 +112,7 @@ describe('Basic RPC tests', () => {
)
})
// SKIP: needs ETH value PR
it
.
skip
(
'
should reject a transaction with higher value than user balance
'
,
async
()
=>
{
it
(
'
should reject a transaction with higher value than user balance
'
,
async
()
=>
{
const
balance
=
await
env
.
l2Wallet
.
getBalance
()
const
tx
=
{
...
DEFAULT_TRANSACTION
,
...
...
@@ -170,8 +168,7 @@ describe('Basic RPC tests', () => {
).
to
.
be
.
rejectedWith
(
'
out of gas
'
)
})
// SKIP: needs ETH value PR
it
.
skip
(
'
should allow eth_calls with nonzero value
'
,
async
()
=>
{
it
(
'
should allow eth_calls with nonzero value
'
,
async
()
=>
{
// Deploy a contract to check msg.value of the call
const
Factory__ValueContext
:
ContractFactory
=
await
ethers
.
getContractFactory
(
'
ValueContext
'
,
wallet
)
...
...
@@ -315,8 +312,7 @@ describe('Basic RPC tests', () => {
})
describe
(
'
eth_getBalance
'
,
()
=>
{
// SKIP: needs ETH value PR
it
.
skip
(
'
should get the OVM_ETH balance
'
,
async
()
=>
{
it
(
'
should get the OVM_ETH balance
'
,
async
()
=>
{
const
rpcBalance
=
await
provider
.
getBalance
(
env
.
l2Wallet
.
address
)
const
contractBalance
=
await
env
.
ovmEth
.
balanceOf
(
env
.
l2Wallet
.
address
)
expect
(
rpcBalance
).
to
.
be
.
deep
.
eq
(
contractBalance
)
...
...
integration-tests/test/shared/env.ts
View file @
2e00002a
...
...
@@ -71,8 +71,7 @@ export class OptimismEnv {
// fund the user if needed
const
balance
=
await
l2Wallet
.
getBalance
()
if
(
balance
.
isZero
())
{
// TEMPORARILY SKIP UNTIL MESSAGE PASSING WORKS
//await fundUser(watcher, l1Bridge, utils.parseEther('20'))
await
fundUser
(
watcher
,
l1Bridge
,
utils
.
parseEther
(
'
20
'
))
}
const
l1Messenger
=
getContractFactory
(
'
iOVM_L1CrossDomainMessenger
'
)
.
connect
(
l1Wallet
)
...
...
integration-tests/test/stress-tests.spec.ts
View file @
2e00002a
...
...
@@ -47,8 +47,7 @@ describe('stress tests', () => {
await
L2SimpleStorage
.
deployTransaction
.
wait
()
})
// SKIP: needs message passing PR
describe
.
skip
(
'
L1 => L2 stress tests
'
,
()
=>
{
describe
(
'
L1 => L2 stress tests
'
,
()
=>
{
const
numTransactions
=
10
it
(
`
${
numTransactions
}
L1 => L2 transactions (serial)`
,
async
()
=>
{
...
...
@@ -84,8 +83,7 @@ describe('stress tests', () => {
}).
timeout
(
STRESS_TEST_TIMEOUT
)
})
// SKIP: needs message passing PR
describe
.
skip
(
'
L2 => L1 stress tests
'
,
()
=>
{
describe
(
'
L2 => L1 stress tests
'
,
()
=>
{
const
numTransactions
=
10
it
(
`
${
numTransactions
}
L2 => L1 transactions (serial)`
,
async
()
=>
{
...
...
l2geth/accounts/abi/bind/bind_test.go
View file @
2e00002a
...
...
@@ -1600,6 +1600,7 @@ var bindTests = []struct {
// Tests that packages generated by the binder can be successfully compiled and
// the requested tester run against it.
func
TestGolangBindings
(
t
*
testing
.
T
)
{
t
.
Skip
(
"test breaks in the ovm - need to research"
)
// Skip the test if no Go command can be found
gocmd
:=
runtime
.
GOROOT
()
+
"/bin/go"
if
!
common
.
FileExist
(
gocmd
)
{
...
...
@@ -1671,6 +1672,7 @@ func TestGolangBindings(t *testing.T) {
// Tests that java binding generated by the binder is exactly matched.
func
TestJavaBindings
(
t
*
testing
.
T
)
{
t
.
Skip
(
"test breaks in the ovm - need to research"
)
var
cases
=
[]
struct
{
name
string
contract
string
...
...
l2geth/accounts/keystore/keystore.go
View file @
2e00002a
...
...
@@ -37,10 +37,10 @@ import (
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rollup/rcfg"
)
var
(
...
...
@@ -83,7 +83,7 @@ func NewKeyStore(keydir string, scryptN, scryptP int) *KeyStore {
keydir
,
_
=
filepath
.
Abs
(
keydir
)
ks
:=
&
KeyStore
{
storage
:
&
keyStorePassphrase
{
keydir
,
scryptN
,
scryptP
,
false
}}
ks
.
init
(
keydir
)
if
vm
.
UsingOVM
{
if
rcfg
.
UsingOVM
{
// Add a deterministic key to the key store so that
// all clique blocks are signed with the same key.
// This change will result in deterministic blocks across
...
...
l2geth/consensus/clique/clique.go
View file @
2e00002a
...
...
@@ -33,12 +33,12 @@ import (
"github.com/ethereum/go-ethereum/consensus/misc"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rollup/rcfg"
"github.com/ethereum/go-ethereum/rpc"
lru
"github.com/hashicorp/golang-lru"
"golang.org/x/crypto/sha3"
...
...
@@ -249,7 +249,7 @@ func (c *Clique) verifyHeader(chain consensus.ChainReader, header *types.Header,
}
number
:=
header
.
Number
.
Uint64
()
if
!
vm
.
UsingOVM
{
if
!
rcfg
.
UsingOVM
{
// Don't waste time checking blocks from the future
if
header
.
Time
>
uint64
(
time
.
Now
()
.
Unix
())
{
return
consensus
.
ErrFutureBlock
...
...
@@ -328,7 +328,7 @@ func (c *Clique) verifyCascadingFields(chain consensus.ChainReader, header *type
// Do not account for timestamps in consensus when running the OVM
// changes. The timestamp must be montonic, meaning that it can be the same
// or increase. L1 dictates the timestamp.
if
!
vm
.
UsingOVM
{
if
!
rcfg
.
UsingOVM
{
if
parent
.
Time
+
c
.
config
.
Period
>
header
.
Time
{
return
ErrInvalidTimestamp
}
...
...
@@ -555,7 +555,7 @@ func (c *Clique) Prepare(chain consensus.ChainReader, header *types.Header) erro
}
// Do not manipulate the timestamps when running with the OVM
if
!
vm
.
UsingOVM
{
if
!
rcfg
.
UsingOVM
{
header
.
Time
=
parent
.
Time
+
c
.
config
.
Period
if
header
.
Time
<
uint64
(
time
.
Now
()
.
Unix
())
{
header
.
Time
=
uint64
(
time
.
Now
()
.
Unix
())
...
...
@@ -640,7 +640,10 @@ func (c *Clique) Seal(chain consensus.ChainReader, block *types.Block, results c
log
.
Trace
(
"Out-of-turn signing requested"
,
"wiggle"
,
common
.
PrettyDuration
(
wiggle
))
}
if
vm
.
UsingOVM
{
// Set the delay to 0 when using the OVM so that blocks are always
// produced instantly. When running in a non-OVM network, the delay prevents
// the creation of invalid blocks.
if
rcfg
.
UsingOVM
{
delay
=
0
}
// Sign all the things!
...
...
l2geth/core/evm.go
View file @
2e00002a
...
...
@@ -23,6 +23,7 @@ import (
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/rollup/rcfg"
)
// DefaultL1MessageSender is the default L1MessageSender value attached to a transaction that is
...
...
@@ -48,7 +49,7 @@ func NewEVMContext(msg Message, header *types.Header, chain ChainContext, author
}
else
{
beneficiary
=
*
author
}
if
vm
.
UsingOVM
{
if
rcfg
.
UsingOVM
{
// When using the OVM, we must:
// (1) Attach the L1MessageSender context value and
// (2) Set the BlockNumber to be the msg.L1BlockNumber
...
...
l2geth/core/genesis.go
View file @
2e00002a
...
...
@@ -34,13 +34,13 @@ import (
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rollup/dump"
"github.com/ethereum/go-ethereum/rollup/rcfg"
)
//go:generate gencodec -type Genesis -field-override genesisSpecMarshaling -out gen_genesis.go
...
...
@@ -352,8 +352,9 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
}
statedb
,
_
:=
state
.
New
(
common
.
Hash
{},
state
.
NewDatabase
(
db
))
if
vm
.
UsingOVM
{
// OVM_ENABLED
// Apply the OVM genesis state, including setting storage dynamically
// in particular system contracts.
if
rcfg
.
UsingOVM
{
ApplyOvmStateToState
(
statedb
,
g
.
Config
.
StateDump
,
g
.
L1CrossDomainMessengerAddress
,
g
.
L1StandardBridgeAddress
,
g
.
AddressManagerOwnerAddress
,
g
.
GasPriceOracleOwnerAddress
,
g
.
L1FeeWalletAddress
,
g
.
ChainID
,
g
.
GasLimit
)
}
...
...
@@ -495,7 +496,7 @@ func DeveloperGenesisBlock(period uint64, faucet, l1XDomainMessengerAddress comm
}
stateDump
:=
dump
.
OvmDump
{}
if
vm
.
UsingOVM
{
if
rcfg
.
UsingOVM
{
// Fetch the state dump from the state dump path
// The system cannot start without a state dump as it depends on
// the ABIs that are included in the state dump. Check that all
...
...
l2geth/core/state/statedb.go
View file @
2e00002a
...
...
@@ -30,7 +30,10 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rollup/dump"
"github.com/ethereum/go-ethereum/rollup/rcfg"
"github.com/ethereum/go-ethereum/trie"
"golang.org/x/crypto/sha3"
)
type
revision
struct
{
...
...
@@ -57,6 +60,15 @@ func (n *proofList) Delete(key []byte) error {
panic
(
"not supported"
)
}
func
GetOVMBalanceKey
(
addr
common
.
Address
)
common
.
Hash
{
position
:=
common
.
Big0
hasher
:=
sha3
.
NewLegacyKeccak256
()
hasher
.
Write
(
common
.
LeftPadBytes
(
addr
.
Bytes
(),
32
))
hasher
.
Write
(
common
.
LeftPadBytes
(
position
.
Bytes
(),
32
))
digest
:=
hasher
.
Sum
(
nil
)
return
common
.
BytesToHash
(
digest
)
}
// StateDBs within the ethereum protocol are used to store anything
// within the merkle trie. StateDBs take care of caching and storing
// nested states. It's the general query interface to retrieve:
...
...
@@ -224,11 +236,19 @@ func (s *StateDB) Empty(addr common.Address) bool {
// Retrieve the balance from the given address or 0 if object not found
func
(
s
*
StateDB
)
GetBalance
(
addr
common
.
Address
)
*
big
.
Int
{
if
rcfg
.
UsingOVM
{
// Get balance from the OVM_ETH contract.
// NOTE: We may remove this feature in a future release.
key
:=
GetOVMBalanceKey
(
addr
)
bal
:=
s
.
GetState
(
dump
.
OvmEthAddress
,
key
)
return
bal
.
Big
()
}
else
{
stateObject
:=
s
.
getStateObject
(
addr
)
if
stateObject
!=
nil
{
return
stateObject
.
Balance
()
}
return
common
.
Big0
}
}
func
(
s
*
StateDB
)
GetNonce
(
addr
common
.
Address
)
uint64
{
...
...
@@ -347,25 +367,55 @@ func (s *StateDB) HasSuicided(addr common.Address) bool {
// AddBalance adds amount to the account associated with addr.
func
(
s
*
StateDB
)
AddBalance
(
addr
common
.
Address
,
amount
*
big
.
Int
)
{
if
rcfg
.
UsingOVM
{
// Mutate the storage slot inside of OVM_ETH to change balances.
// Note that we don't need to check for overflows or underflows here because the code that
// uses this codepath already checks for them. You can follow the original codepath below
// (stateObject.AddBalance) to confirm that there are no checks being performed here.
key
:=
GetOVMBalanceKey
(
addr
)
value
:=
s
.
GetState
(
dump
.
OvmEthAddress
,
key
)
bal
:=
value
.
Big
()
bal
=
bal
.
Add
(
bal
,
amount
)
s
.
SetState
(
dump
.
OvmEthAddress
,
key
,
common
.
BigToHash
(
bal
))
}
else
{
stateObject
:=
s
.
GetOrNewStateObject
(
addr
)
if
stateObject
!=
nil
{
stateObject
.
AddBalance
(
amount
)
}
}
}
// SubBalance subtracts amount from the account associated with addr.
func
(
s
*
StateDB
)
SubBalance
(
addr
common
.
Address
,
amount
*
big
.
Int
)
{
if
rcfg
.
UsingOVM
{
// Mutate the storage slot inside of OVM_ETH to change balances.
// Note that we don't need to check for overflows or underflows here because the code that
// uses this codepath already checks for them. You can follow the original codepath below
// (stateObject.SubBalance) to confirm that there are no checks being performed here.
key
:=
GetOVMBalanceKey
(
addr
)
value
:=
s
.
GetState
(
dump
.
OvmEthAddress
,
key
)
bal
:=
value
.
Big
()
bal
=
bal
.
Sub
(
bal
,
amount
)
s
.
SetState
(
dump
.
OvmEthAddress
,
key
,
common
.
BigToHash
(
bal
))
}
else
{
stateObject
:=
s
.
GetOrNewStateObject
(
addr
)
if
stateObject
!=
nil
{
stateObject
.
SubBalance
(
amount
)
}
}
}
func
(
s
*
StateDB
)
SetBalance
(
addr
common
.
Address
,
amount
*
big
.
Int
)
{
if
rcfg
.
UsingOVM
{
// Mutate the storage slot inside of OVM_ETH to change balances.
key
:=
GetOVMBalanceKey
(
addr
)
s
.
SetState
(
dump
.
OvmEthAddress
,
key
,
common
.
BigToHash
(
amount
))
}
else
{
stateObject
:=
s
.
GetOrNewStateObject
(
addr
)
if
stateObject
!=
nil
{
stateObject
.
SetBalance
(
amount
)
}
}
}
func
(
s
*
StateDB
)
SetNonce
(
addr
common
.
Address
,
nonce
uint64
)
{
...
...
l2geth/core/state_processor.go
View file @
2e00002a
...
...
@@ -25,6 +25,7 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rollup/rcfg"
)
// StateProcessor is a basic Processor, which takes care of transitioning
...
...
@@ -87,7 +88,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
// indicating the block was invalid.
func
ApplyTransaction
(
config
*
params
.
ChainConfig
,
bc
ChainContext
,
author
*
common
.
Address
,
gp
*
GasPool
,
statedb
*
state
.
StateDB
,
header
*
types
.
Header
,
tx
*
types
.
Transaction
,
usedGas
*
uint64
,
cfg
vm
.
Config
)
(
*
types
.
Receipt
,
error
)
{
msg
,
err
:=
tx
.
AsMessage
(
types
.
MakeSigner
(
config
,
header
.
Number
))
if
vm
.
UsingOVM
{
if
rcfg
.
UsingOVM
{
if
err
!=
nil
{
// This should only be allowed to pass if the transaction is in the ctc
// already. The presence of `Index` should specify this.
...
...
l2geth/core/state_transition.go
View file @
2e00002a
...
...
@@ -27,6 +27,7 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rollup/rcfg"
)
var
(
...
...
@@ -180,10 +181,8 @@ func (st *StateTransition) preCheck() error {
if
st
.
msg
.
CheckNonce
()
{
nonce
:=
st
.
state
.
GetNonce
(
st
.
msg
.
From
())
if
nonce
<
st
.
msg
.
Nonce
()
{
// Skip the nonce check for L1 to L2 transactions. They do not
// increment a nonce in the state and they also ecrecover to
// `address(0)`
if
vm
.
UsingOVM
{
if
rcfg
.
UsingOVM
{
// The nonce never increments for L1ToL2 txs
if
st
.
msg
.
QueueOrigin
()
==
types
.
QueueOriginL1ToL2
{
return
st
.
buyGas
()
}
...
...
l2geth/core/tx_pool.go
View file @
2e00002a
...
...
@@ -29,11 +29,11 @@ import (
"github.com/ethereum/go-ethereum/common/prque"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rollup/rcfg"
)
const
(
...
...
@@ -554,7 +554,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
return
ErrUnderpriced
}
// Ensure the transaction adheres to nonce ordering
if
vm
.
UsingOVM
{
if
rcfg
.
UsingOVM
{
if
pool
.
currentState
.
GetNonce
(
from
)
!=
tx
.
Nonce
()
{
return
ErrNonceTooLow
}
...
...
l2geth/eth/api_backend.go
View file @
2e00002a
...
...
@@ -37,6 +37,7 @@ import (
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rollup/rcfg"
"github.com/ethereum/go-ethereum/rpc"
)
...
...
@@ -267,7 +268,13 @@ func (b *EthAPIBackend) GetTd(blockHash common.Hash) *big.Int {
}
func
(
b
*
EthAPIBackend
)
GetEVM
(
ctx
context
.
Context
,
msg
core
.
Message
,
state
*
state
.
StateDB
,
header
*
types
.
Header
)
(
*
vm
.
EVM
,
func
()
error
,
error
)
{
// This was removed upstream:
// https://github.com/ethereum/go-ethereum/commit/39f502329fac4640cfb71959c3496f19ea88bc85#diff-9886da3412b43831145f62cec6e895eb3613a175b945e5b026543b7463454603
// We're throwing this behind a UsingOVM flag for now as to not break
// any tests that may depend on this behavior.
if
!
rcfg
.
UsingOVM
{
state
.
SetBalance
(
msg
.
From
(),
math
.
MaxBig256
)
}
vmError
:=
func
()
error
{
return
nil
}
context
:=
core
.
NewEVMContext
(
msg
,
header
,
b
.
eth
.
BlockChain
(),
nil
)
...
...
l2geth/eth/backend.go
View file @
2e00002a
...
...
@@ -26,8 +26,6 @@ import (
"sync"
"sync/atomic"
"github.com/ethereum/go-ethereum/rollup"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -53,6 +51,8 @@ import (
"github.com/ethereum/go-ethereum/p2p/enr"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rollup"
"github.com/ethereum/go-ethereum/rollup/rcfg"
"github.com/ethereum/go-ethereum/rpc"
)
...
...
@@ -223,8 +223,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
eth
.
miner
=
miner
.
New
(
eth
,
&
config
.
Miner
,
chainConfig
,
eth
.
EventMux
(),
eth
.
engine
,
eth
.
isLocalBlock
)
eth
.
miner
.
SetExtra
(
makeExtraData
(
config
.
Miner
.
ExtraData
))
log
.
Info
(
"Backend Config"
,
"max-calldata-size"
,
config
.
Rollup
.
MaxCallDataSize
,
"gas-limit"
,
config
.
Rollup
.
GasLimit
,
"is-verifier"
,
config
.
Rollup
.
IsVerifier
,
"using-ovm"
,
vm
.
UsingOVM
)
eth
.
APIBackend
=
&
EthAPIBackend
{
ctx
.
ExtRPCEnabled
(),
eth
,
nil
,
nil
,
config
.
Rollup
.
IsVerifier
,
config
.
Rollup
.
GasLimit
,
vm
.
UsingOVM
,
config
.
Rollup
.
MaxCallDataSize
}
log
.
Info
(
"Backend Config"
,
"max-calldata-size"
,
config
.
Rollup
.
MaxCallDataSize
,
"gas-limit"
,
config
.
Rollup
.
GasLimit
,
"is-verifier"
,
config
.
Rollup
.
IsVerifier
,
"using-ovm"
,
rcfg
.
UsingOVM
)
eth
.
APIBackend
=
&
EthAPIBackend
{
ctx
.
ExtRPCEnabled
(),
eth
,
nil
,
nil
,
config
.
Rollup
.
IsVerifier
,
config
.
Rollup
.
GasLimit
,
rcfg
.
UsingOVM
,
config
.
Rollup
.
MaxCallDataSize
}
gpoParams
:=
config
.
GPO
if
gpoParams
.
Default
==
nil
{
gpoParams
.
Default
=
config
.
Miner
.
GasPrice
...
...
@@ -238,7 +238,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
}
func
makeExtraData
(
extra
[]
byte
)
[]
byte
{
if
vm
.
UsingOVM
{
if
rcfg
.
UsingOVM
{
// Make the extradata deterministic
extra
,
_
=
rlp
.
EncodeToBytes
([]
interface
{}{
uint
(
params
.
VersionMajor
<<
16
|
params
.
VersionMinor
<<
8
|
params
.
VersionPatch
),
...
...
l2geth/internal/ethapi/api.go
View file @
2e00002a
...
...
@@ -44,15 +44,11 @@ import (
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rollup/
fees
"
"github.com/ethereum/go-ethereum/rollup/
rcfg
"
"github.com/ethereum/go-ethereum/rpc"
"github.com/tyler-smith/go-bip39"
)
const
(
defaultGasPrice
=
params
.
Wei
*
fees
.
TxGasPrice
)
var
errOVMUnsupported
=
errors
.
New
(
"OVM: Unsupported RPC Method"
)
// TEMPORARY: Set the gas price to 0 until message passing and ETH value work again.
...
...
@@ -848,7 +844,7 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo
log
.
Warn
(
"Caller gas above allowance, capping"
,
"requested"
,
gas
,
"cap"
,
globalGasCap
)
gas
=
globalGasCap
.
Uint64
()
}
gasPrice
:=
new
(
big
.
Int
)
.
SetUint64
(
defaultGasPrice
)
gasPrice
:=
new
(
big
.
Int
)
if
args
.
GasPrice
!=
nil
{
gasPrice
=
args
.
GasPrice
.
ToInt
()
}
...
...
@@ -868,7 +864,7 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo
// or else the result of `eth_call` will not be correct.
blockNumber
:=
header
.
Number
timestamp
:=
header
.
Time
if
vm
.
UsingOVM
{
if
rcfg
.
UsingOVM
{
block
,
err
:=
b
.
BlockByNumber
(
ctx
,
rpc
.
BlockNumber
(
header
.
Number
.
Uint64
()))
if
err
!=
nil
{
return
nil
,
0
,
false
,
err
...
...
@@ -1596,7 +1592,7 @@ func SubmitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (c
// SendTransaction creates a transaction for the given argument, sign it and submit it to the
// transaction pool.
func
(
s
*
PublicTransactionPoolAPI
)
SendTransaction
(
ctx
context
.
Context
,
args
SendTxArgs
)
(
common
.
Hash
,
error
)
{
if
vm
.
UsingOVM
{
if
rcfg
.
UsingOVM
{
return
common
.
Hash
{},
errOVMUnsupported
}
// Look up the wallet containing the requested signer
...
...
@@ -1631,7 +1627,7 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen
// FillTransaction fills the defaults (nonce, gas, gasPrice) on a given unsigned transaction,
// and returns it to the caller for further processing (signing + broadcast)
func
(
s
*
PublicTransactionPoolAPI
)
FillTransaction
(
ctx
context
.
Context
,
args
SendTxArgs
)
(
*
SignTransactionResult
,
error
)
{
if
vm
.
UsingOVM
{
if
rcfg
.
UsingOVM
{
return
nil
,
errOVMUnsupported
}
// Set some sanity defaults and terminate on failure
...
...
@@ -1678,7 +1674,7 @@ func (s *PublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, encod
//
// https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
func
(
s
*
PublicTransactionPoolAPI
)
Sign
(
addr
common
.
Address
,
data
hexutil
.
Bytes
)
(
hexutil
.
Bytes
,
error
)
{
if
vm
.
UsingOVM
{
if
rcfg
.
UsingOVM
{
return
nil
,
errOVMUnsupported
}
// Look up the wallet containing the requested signer
...
...
@@ -1706,7 +1702,7 @@ type SignTransactionResult struct {
// The node needs to have the private key of the account corresponding with
// the given from address and it needs to be unlocked.
func
(
s
*
PublicTransactionPoolAPI
)
SignTransaction
(
ctx
context
.
Context
,
args
SendTxArgs
)
(
*
SignTransactionResult
,
error
)
{
if
vm
.
UsingOVM
{
if
rcfg
.
UsingOVM
{
return
nil
,
errOVMUnsupported
}
if
args
.
Gas
==
nil
{
...
...
l2geth/rollup/dump/constants.go
0 → 100644
View file @
2e00002a
package
dump
import
(
"github.com/ethereum/go-ethereum/common"
)
var
OvmEthAddress
=
common
.
HexToAddress
(
"0x4200000000000000000000000000000000000006"
)
l2geth/rollup/rcfg/config.go
0 → 100644
View file @
2e00002a
package
rcfg
import
(
"os"
)
// UsingOVM is used to enable or disable functionality necessary for the OVM.
var
UsingOVM
bool
func
init
()
{
UsingOVM
=
os
.
Getenv
(
"USING_OVM"
)
==
"true"
}
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