Skip to content

Commit

Permalink
Merge branch 'pedro/fix_build' into pedro/add_new_node_fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
otherview committed Dec 27, 2023
2 parents bda3bcf + 6f9c00e commit 5d1fd19
Show file tree
Hide file tree
Showing 37 changed files with 277 additions and 111 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ jobs:
integration/.build/noderunner/noderunner-*.txt
integration/.build/wallet_extension/wal-ext-*.txt
integration/.build/eth2/*
integration/.build/faucet/*
integration/.build/obscuroscan/*
integration/.build/tengateway/*
integration/.build/smartcontracts/*
retention-days: 1


Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// This is required in CI/CD - look at testnet-deploy-contracts.sh for more information.
// depends on grep -e MessageBusAddress and a positional cut of the address
console.log(`MessageBusAddress= ${busAddress}`);
console.log(`L1Start=${mgmtContractDeployment.receipt.blockHash}`)
console.log(`L1Start= ${mgmtContractDeployment.receipt.blockHash}`)
};

export default func;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
return l2Network.deployments.execute("CrossChainMessenger", {
from: l2Accounts.deployer,
log: true,
gasLimit: 1024_000_000
gasLimit: 5_000_000
}, "relayMessage", msg);
};

Expand Down
6 changes: 4 additions & 2 deletions go/config/enclave_cli_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const (
MaxRollupSizeFlag = "maxRollupSize"
L2BaseFeeFlag = "l2BaseFee"
L2CoinbaseFlag = "l2Coinbase"
L2GasLimitFlag = "l2GasLimit"
GasBatchExecutionLimit = "gasBatchExecutionLimit"
GasLocalExecutionCapFlag = "gasLocalExecutionCap"
)

// EnclaveFlags are the flags that the enclave can receive
Expand All @@ -54,13 +55,14 @@ var EnclaveFlags = map[string]*flag.TenFlag{
MaxRollupSizeFlag: flag.NewUint64Flag(MaxRollupSizeFlag, 1024*64, "The maximum size a rollup is allowed to reach"),
L2BaseFeeFlag: flag.NewUint64Flag(L2BaseFeeFlag, 1, ""),
L2CoinbaseFlag: flag.NewStringFlag(L2CoinbaseFlag, "0xd6C9230053f45F873Cb66D8A02439380a37A4fbF", ""),
L2GasLimitFlag: flag.NewUint64Flag(L2GasLimitFlag, 9e18, ""),
GasBatchExecutionLimit: flag.NewUint64Flag(GasBatchExecutionLimit, 30_000_000, "Max gas that can be executed in a single batch"),
ObscuroGenesisFlag: flag.NewStringFlag(ObscuroGenesisFlag, "", "The json string with the obscuro genesis"),
L1ChainIDFlag: flag.NewInt64Flag(L1ChainIDFlag, 1337, "An integer representing the unique chain id of the Ethereum chain used as an L1 (default 1337)"),
ObscuroChainIDFlag: flag.NewInt64Flag(ObscuroChainIDFlag, 443, "An integer representing the unique chain id of the Obscuro chain (default 443)"),
UseInMemoryDBFlag: flag.NewBoolFlag(UseInMemoryDBFlag, true, "Whether the enclave will use an in-memory DB rather than persist data"),
ProfilerEnabledFlag: flag.NewBoolFlag(ProfilerEnabledFlag, false, "Runs a profiler instance (Defaults to false)"),
DebugNamespaceEnabledFlag: flag.NewBoolFlag(DebugNamespaceEnabledFlag, false, "Whether the debug namespace is enabled"),
GasLocalExecutionCapFlag: flag.NewUint64Flag(GasLocalExecutionCapFlag, 40_000_000, "Max gas usage when executing local transactions"),
}

// enclaveRestrictedFlags are the flags that the enclave can receive ONLY over the Ego signed enclave.json
Expand Down
10 changes: 6 additions & 4 deletions go/config/enclave_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ type EnclaveConfig struct {
// to include a transaction if it goes above it
MaxRollupSize uint64

GasPaymentAddress gethcommon.Address
BaseFee *big.Int
GasLimit *big.Int
GasPaymentAddress gethcommon.Address
BaseFee *big.Int
GasBatchExecutionLimit uint64
GasLocalExecutionCapFlag uint64
}

func NewConfigFromFlags(cliFlags map[string]*flag.TenFlag) (*EnclaveConfig, error) {
Expand Down Expand Up @@ -184,7 +185,8 @@ func newConfig(flags map[string]*flag.TenFlag) (*EnclaveConfig, error) {
cfg.MaxRollupSize = flags[MaxRollupSizeFlag].Uint64()
cfg.BaseFee = big.NewInt(0).SetUint64(flags[L2BaseFeeFlag].Uint64())
cfg.GasPaymentAddress = gethcommon.HexToAddress(flags[L2CoinbaseFlag].String())
cfg.GasLimit = big.NewInt(0).SetUint64(flags[L2GasLimitFlag].Uint64())
cfg.GasBatchExecutionLimit = flags[GasBatchExecutionLimit].Uint64()
cfg.GasLocalExecutionCapFlag = flags[GasLocalExecutionCapFlag].Uint64()

return cfg, nil
}
6 changes: 3 additions & 3 deletions go/config/enclave_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestCLIFlagTypes(t *testing.T) {
err = flag.CommandLine.Set(MinGasPriceFlag, "3333")
require.NoError(t, err)

err = flag.CommandLine.Set(L2GasLimitFlag, "222222")
err = flag.CommandLine.Set(GasBatchExecutionLimit, "222222")
require.NoError(t, err)

flag.Parse()
Expand All @@ -50,7 +50,7 @@ func TestCLIFlagTypes(t *testing.T) {
require.Equal(t, true, flags[WillAttestFlag].Bool())
require.Equal(t, 123, flags[LogLevelFlag].Int())
require.Equal(t, int64(3333), flags[MinGasPriceFlag].Int64())
require.Equal(t, uint64(222222), flags[L2GasLimitFlag].Uint64())
require.Equal(t, uint64(222222), flags[GasBatchExecutionLimit].Uint64())

enclaveConfig, err := newConfig(flags)
require.NoError(t, err)
Expand All @@ -59,7 +59,7 @@ func TestCLIFlagTypes(t *testing.T) {
require.Equal(t, true, enclaveConfig.WillAttest)
require.Equal(t, 123, enclaveConfig.LogLevel)
require.Equal(t, big.NewInt(3333), enclaveConfig.MinGasPrice)
require.Equal(t, big.NewInt(222222), enclaveConfig.GasLimit)
require.Equal(t, uint64(222222), enclaveConfig.GasBatchExecutionLimit)
}

func TestRestrictedMode(t *testing.T) {
Expand Down
28 changes: 19 additions & 9 deletions go/enclave/components/batch_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ type batchExecutor struct {

// stateDBMutex - used to protect calls to stateDB.Commit as it is not safe for async access.
stateDBMutex sync.Mutex

batchGasLimit uint64 // max execution gas allowed in a batch
}

func NewBatchExecutor(
Expand All @@ -50,6 +52,7 @@ func NewBatchExecutor(
genesis *genesis.Genesis,
gasOracle gas.Oracle,
chainConfig *params.ChainConfig,
batchGasLimit uint64,
logger gethlog.Logger,
) BatchExecutor {
return &batchExecutor{
Expand All @@ -60,6 +63,7 @@ func NewBatchExecutor(
logger: logger,
gasOracle: gasOracle,
stateDBMutex: sync.Mutex{},
batchGasLimit: batchGasLimit,
}
}

Expand Down Expand Up @@ -168,6 +172,7 @@ func (executor *batchExecutor) ComputeBatch(context *BatchExecutionContext, fail
if err != nil {
return nil, fmt.Errorf("could not create stateDB. Cause: %w", err)
}
snap := stateDB.Snapshot()

var messages common.CrossChainMessages
var transfers common.ValueTransferEvents
Expand Down Expand Up @@ -217,6 +222,8 @@ func (executor *batchExecutor) ComputeBatch(context *BatchExecutionContext, fail
len(crossChainTransactions) == 0 &&
len(messages) == 0 &&
len(transfers) == 0 {
// revert any unexpected mutation to the statedb
stateDB.RevertToSnapshot(snap)
return nil, ErrNoTransactionsToProcess
}

Expand Down Expand Up @@ -298,18 +305,12 @@ func (executor *batchExecutor) CreateGenesisState(
timeNow uint64,
coinbase gethcommon.Address,
baseFee *big.Int,
gasLimit *big.Int,
) (*core.Batch, *types.Transaction, error) {
preFundGenesisState, err := executor.genesis.GetGenesisRoot(executor.storage)
if err != nil {
return nil, nil, err
}

limit := params.MaxGasLimit / 6
if gasLimit != nil {
limit = gasLimit.Uint64()
}

genesisBatch := &core.Batch{
Header: &common.BatchHeader{
ParentHash: common.L2BatchHash{},
Expand All @@ -323,7 +324,7 @@ func (executor *batchExecutor) CreateGenesisState(
Time: timeNow,
Coinbase: coinbase,
BaseFee: baseFee,
GasLimit: limit, // todo (@siliev) - does the batch header need uint64?
GasLimit: executor.batchGasLimit,
},
Transactions: []*common.L2Tx{},
}
Expand Down Expand Up @@ -408,8 +409,17 @@ func (executor *batchExecutor) processTransactions(
var executedTransactions []*common.L2Tx
var excludedTransactions []*common.L2Tx
var txReceipts []*types.Receipt

txResults := evm.ExecuteTransactions(txs, stateDB, batch.Header, executor.storage, cc, tCount, noBaseFee, executor.logger)
txResults := evm.ExecuteTransactions(
txs,
stateDB,
batch.Header,
executor.storage,
cc,
tCount,
noBaseFee,
executor.batchGasLimit,
executor.logger,
)
for _, tx := range txs {
result, f := txResults[tx.Hash()]
if !f {
Expand Down
2 changes: 1 addition & 1 deletion go/enclave/components/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type BatchExecutor interface {
// CreateGenesisState - will create and commit the genesis state in the stateDB for the given block hash,
// and uint64 timestamp representing the time now. In this genesis state is where one can
// find preallocated funds for faucet. TODO - make this an option
CreateGenesisState(common.L1BlockHash, uint64, gethcommon.Address, *big.Int, *big.Int) (*core.Batch, *types.Transaction, error)
CreateGenesisState(common.L1BlockHash, uint64, gethcommon.Address, *big.Int) (*core.Batch, *types.Transaction, error)
}

type BatchRegistry interface {
Expand Down
1 change: 0 additions & 1 deletion go/enclave/components/rollup_compression.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,6 @@ func (rc *RollupCompression) executeAndSaveIncompleteBatches(calldataRollupHeade
incompleteBatch.time,
calldataRollupHeader.Coinbase,
calldataRollupHeader.BaseFee,
big.NewInt(0).SetUint64(calldataRollupHeader.GasLimit),
)
if err != nil {
return err
Expand Down
35 changes: 16 additions & 19 deletions go/enclave/enclave.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ type enclaveImpl struct {
service nodetype.NodeType
registry components.BatchRegistry

// todo (#627) - use the ethconfig.Config instead
GlobalGasCap uint64 // 5_000_000_000, // todo (#627) - make config
BaseFee *big.Int // gethcommon.Big0,

mgmtContractLib mgmtcontractlib.MgmtContractLib
attestationProvider components.AttestationProvider // interface for producing attestation reports and verifying them

Expand Down Expand Up @@ -184,7 +180,7 @@ func NewEnclave(

gasOracle := gas.NewGasOracle()
blockProcessor := components.NewBlockProcessor(storage, crossChainProcessors, gasOracle, logger)
batchExecutor := components.NewBatchExecutor(storage, crossChainProcessors, genesis, gasOracle, chainConfig, logger)
batchExecutor := components.NewBatchExecutor(storage, crossChainProcessors, genesis, gasOracle, chainConfig, config.GasBatchExecutionLimit, logger)
sigVerifier, err := components.NewSignatureValidator(config.SequencerID, storage)
registry := components.NewBatchRegistry(storage, logger)
rProducer := components.NewRollupProducer(config.SequencerID, storage, registry, logger)
Expand Down Expand Up @@ -222,7 +218,7 @@ func NewEnclave(
MaxBatchSize: config.MaxBatchSize,
MaxRollupSize: config.MaxRollupSize,
GasPaymentAddress: config.GasPaymentAddress,
BatchGasLimit: config.GasLimit,
BatchGasLimit: config.GasBatchExecutionLimit,
BaseFee: config.BaseFee,
},
blockchain,
Expand All @@ -237,6 +233,7 @@ func NewEnclave(
genesis,
logger,
registry,
config.GasLocalExecutionCapFlag,
)

// ensure cached chain state data is up-to-date using the persisted batch data
Expand Down Expand Up @@ -275,9 +272,6 @@ func NewEnclave(
registry: registry,
service: service,

GlobalGasCap: 5_000_000_000, // todo (#627) - make config
BaseFee: gethcommon.Big0,

mainMutex: sync.Mutex{},
}
}
Expand Down Expand Up @@ -691,15 +685,18 @@ func (e *enclaveImpl) GetTransactionCount(encryptedParams common.EncryptedParams
}

var nonce uint64
l2Head, err := e.storage.FetchBatchBySeqNo(e.registry.HeadBatchSeq().Uint64())
if err == nil {
// todo - we should return an error when head state is not available, but for current test situations with race
// conditions we allow it to return zero while head state is uninitialized
s, err := e.storage.CreateStateDB(l2Head.Hash())
if err != nil {
return nil, responses.ToInternalError(err)
headBatch := e.registry.HeadBatchSeq()
if headBatch != nil {
l2Head, err := e.storage.FetchBatchBySeqNo(headBatch.Uint64())
if err == nil {
// todo - we should return an error when head state is not available, but for current test situations with race
// conditions we allow it to return zero while head state is uninitialized
s, err := e.storage.CreateStateDB(l2Head.Hash())
if err != nil {
return nil, responses.ToInternalError(err)
}
nonce = s.GetNonce(address)
}
nonce = s.GetNonce(address)
}

encoded := hexutil.EncodeUint64(nonce)
Expand Down Expand Up @@ -1028,7 +1025,7 @@ func (e *enclaveImpl) EstimateGas(encryptedParams common.EncryptedParamsEstimate
return responses.AsEncryptedError(err, vkHandler), nil
}

executionGasEstimate, err := e.DoEstimateGas(callMsg, blockNumber, e.GlobalGasCap)
executionGasEstimate, err := e.DoEstimateGas(callMsg, blockNumber, e.config.GasLocalExecutionCapFlag)
if err != nil {
err = fmt.Errorf("unable to estimate transaction - %w", err)

Expand Down Expand Up @@ -1155,7 +1152,7 @@ func (e *enclaveImpl) DoEstimateGas(args *gethapi.TransactionArgs, blkNumber *ge
}
hi = block.GasLimit()
*/
hi = e.GlobalGasCap
hi = e.config.GasLocalExecutionCapFlag
}
// Normalize the max fee per gas the call is willing to spend.
var feeCap *big.Int
Expand Down
19 changes: 11 additions & 8 deletions go/enclave/evm/evm_facade.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package evm
import (
"errors"
"fmt"
"math"
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi"
Expand Down Expand Up @@ -38,9 +37,11 @@ func ExecuteTransactions(
chainConfig *params.ChainConfig,
fromTxIndex int,
noBaseFee bool,
batchGasLimit uint64,
logger gethlog.Logger,
) map[common.TxHash]interface{} {
chain, vmCfg, gp := initParams(storage, noBaseFee, logger)
chain, vmCfg := initParams(storage, noBaseFee, logger)
gp := gethcore.GasPool(batchGasLimit)
zero := uint64(0)
usedGas := &zero
result := map[common.TxHash]interface{}{}
Expand All @@ -57,7 +58,7 @@ func ExecuteTransactions(
s,
chainConfig,
chain,
gp,
&gp,
ethHeader,
t,
usedGas,
Expand Down Expand Up @@ -157,6 +158,7 @@ func ExecuteObsCall(
header *common.BatchHeader,
storage storage.Storage,
chainConfig *params.ChainConfig,
gasEstimationCap uint64,
logger gethlog.Logger,
) (*gethcore.ExecutionResult, error) {
noBaseFee := true
Expand All @@ -166,7 +168,9 @@ func ExecuteObsCall(

defer core.LogMethodDuration(logger, measure.NewStopwatch(), "evm_facade.go:ObsCall()")

chain, vmCfg, gp := initParams(storage, noBaseFee, nil)
gp := gethcore.GasPool(gasEstimationCap)
gp.SetGas(gasEstimationCap)
chain, vmCfg := initParams(storage, noBaseFee, nil)
ethHeader, err := gethencoding.CreateEthHeaderForBatch(header, secret(storage))
if err != nil {
return nil, err
Expand All @@ -177,7 +181,7 @@ func ExecuteObsCall(
txContext := gethcore.NewEVMTxContext(msg)
vmenv := vm.NewEVM(blockContext, txContext, s, chainConfig, vmCfg)

result, err := gethcore.ApplyMessage(vmenv, msg, gp)
result, err := gethcore.ApplyMessage(vmenv, msg, &gp)
// Follow the same error check structure as in geth
// 1 - vmError / stateDB err check
// 2 - evm.Cancelled() todo (#1576) - support the ability to cancel function call if it takes too long
Expand All @@ -202,12 +206,11 @@ func ExecuteObsCall(
return result, nil
}

func initParams(storage storage.Storage, noBaseFee bool, l gethlog.Logger) (*ObscuroChainContext, vm.Config, *gethcore.GasPool) {
func initParams(storage storage.Storage, noBaseFee bool, l gethlog.Logger) (*ObscuroChainContext, vm.Config) {
vmCfg := vm.Config{
NoBaseFee: noBaseFee,
}
gp := gethcore.GasPool(math.MaxUint64)
return NewObscuroChainContext(storage, l), vmCfg, &gp
return NewObscuroChainContext(storage, l), vmCfg
}

// todo (#1053) - this is currently just returning the shared secret
Expand Down
Loading

0 comments on commit 5d1fd19

Please sign in to comment.