Skip to content

Commit

Permalink
Working version with baseFee == 1
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanIliev545 committed Sep 19, 2023
1 parent 8db2c56 commit 4500885
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 33 deletions.
13 changes: 7 additions & 6 deletions contracts/config/networks.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"localGeth": {
"url": "http://127.0.0.1:8025",
"url": "http://127.0.0.1:37000",
"deploy": [
"deployment_scripts/core/layer1/",
"deployment_scripts/testnet/layer1/",
Expand All @@ -13,15 +13,16 @@
},
"localObscuro": {
"chainId": 777,
"url": "http://127.0.0.1:3000/v1",
"obscuroEncRpcUrl": "ws://127.0.0.1:81",
"gasPrice": 2000000000,
"url": "http://127.0.0.1:3000/v1/",
"obscuroEncRpcUrl": "ws://127.0.0.1:37901",
"companionNetworks" : {
"layer1" : "localGeth"
},
"deploy": [
"deployment_scripts/core/layer2/",
"deployment_scripts/bridge/layer2/",
"deployment_scripts/messenger/layer1",
"deployment_scripts/messenger/layer2",
"deployment_scripts/bridge/",
"deployment_scripts/testnet/layer1/",
"deployment_scripts/testnet/layer2/"
],
"accounts": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer } = await hre.companionNetworks.layer1.getNamedAccounts();

// Read the message bus address from the management contract deployment.
const messageBusAddress : string = process.env.MESSAGE_BUS_ADDRESS!!
const messageBusAddress : string = process.env.MESSAGE_BUS_ADDRESS || "0xa1fdA5f6Df55a326f5f4300F3A716317f0f03110"
console.log(`Message Bus address ${messageBusAddress}`);

// Setup the cross chain messenger and point it to the message bus from the management contract to be used for validation
await deployments.deploy('CrossChainMessenger', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// Get the prefunded L2 deployer account to use for deploying.
const {deployer} = await getNamedAccounts();

console.log(`Deployer acc ${deployer}`);

// TODO: Remove hardcoded L2 message bus address when properly exposed.
const busAddress = hre.ethers.utils.getAddress("0x526c84529b2b8c11f57d93d3f5537aca3aecef9b")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,9 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
await new Promise(async (resolve, fail)=> {
setTimeout(fail, 30_000)
const messageBusContract = (await hre.ethers.getContractAt('MessageBus', '0x526c84529b2b8c11f57d93d3f5537aca3aecef9b'));
var gasLimit = await messageBusContract.estimateGas.verifyMessageFinalized(messages[1], {
from: l2Accounts.deployer,
})
const gasPrice = await l2Network.ethers.provider.getGasPrice()
const modifiedGasLimit = gasLimit.toNumber() + gasLimit.toNumber()
console.log("Gas limit for call: " + modifiedGasLimit.toString())

try {
while (await messageBusContract.callStatic.verifyMessageFinalized(messages[1], {
from: l2Accounts.deployer,
maxFeePerGas: gasPrice,
gasLimit: modifiedGasLimit,
maxFeePerGas: 2,
}) != true) {
console.log(`Messages not stored on L2 yet, retrying...`);
await sleep(1_000);
Expand Down
6 changes: 4 additions & 2 deletions contracts/tasks/wallet-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ task("obscuro:wallet-extension:start:local")
.setAction(async function(args, hre) {
const nodeUrl = url.parse(args.rpcUrl)

if (args.withStdOut) {
/* if (args.withStdOut) {
console.log(`Node url = ${JSON.stringify(nodeUrl, null, " ")}`);
}
}*/

const walletExtensionPath = path.resolve(hre.config.paths.root, "../tools/walletextension/bin/wallet_extension_linux");
const weProcess = spawn(walletExtensionPath, [
Expand Down Expand Up @@ -149,6 +149,7 @@ task("obscuro:wallet-extension:add-key", "Creates a viewing key for a specifiec
}
}, (response)=>{
if (response.statusCode != 200) {
console.error(response);
fail(response.statusCode);
return;
}
Expand Down Expand Up @@ -184,6 +185,7 @@ task("obscuro:wallet-extension:add-key", "Creates a viewing key for a specifiec
if (response.statusCode == 200) {
resolve(response.statusCode);
} else {
console.log(response.statusMessage)
fail(response.statusCode);
}
});
Expand Down
2 changes: 1 addition & 1 deletion go/config/enclave_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func DefaultEnclaveConfig() *EnclaveConfig {
MaxBatchSize: 1024 * 25,
MaxRollupSize: 1024 * 64,
GasPaymentAddress: gethcommon.BigToAddress(gethcommon.Big2),
BaseFee: new(big.Int).SetUint64(0),
BaseFee: new(big.Int).SetUint64(1),
GasLimit: new(big.Int).SetUint64(params.MaxGasLimit),
}
}
37 changes: 25 additions & 12 deletions go/enclave/components/batch_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ func NewBatchExecutor(
// payL1Fees - this function modifies the state db according to the transactions contained within the batch context
// in order to substract gas fees from the balance. It returns a list of the transactions that have prepaid for their L1
// publishing costs.
func (executor *batchExecutor) payL1Fees(stateDB *state.StateDB, context *BatchExecutionContext) common.L2Transactions {
func (executor *batchExecutor) payL1Fees(stateDB *state.StateDB, context *BatchExecutionContext) (common.L2Transactions, common.L2Transactions) {
transactions := make(common.L2Transactions, 0)
freeTransactions := make(common.L2Transactions, 0)
block, _ := executor.storage.FetchBlock(context.BlockPtr)

for _, tx := range context.Transactions {
Expand All @@ -85,17 +86,20 @@ func (executor *batchExecutor) payL1Fees(stateDB *state.StateDB, context *BatchE
isFreeTransaction := tx.GasFeeCap().Cmp(gethcommon.Big0) == 0
isFreeTransaction = isFreeTransaction && tx.GasPrice().Cmp(gethcommon.Big0) == 0

if !isFreeTransaction {
if accBalance.Cmp(cost) == -1 {
executor.logger.Info("insufficient account balance for tx", log.TxKey, tx.Hash(), "addr", sender.Hex())
continue
}
stateDB.SubBalance(*sender, cost)
stateDB.AddBalance(context.Creator, cost)
if isFreeTransaction {
freeTransactions = append(freeTransactions, tx)
continue
}
if accBalance.Cmp(cost) == -1 {
executor.logger.Info("insufficient account balance for tx", log.TxKey, tx.Hash(), "addr", sender.Hex())
continue
}
stateDB.SubBalance(*sender, cost)
stateDB.AddBalance(context.Creator, cost)

transactions = append(transactions, tx)
}
return transactions
return transactions, freeTransactions
}

func (executor *batchExecutor) ComputeBatch(context *BatchExecutionContext) (*ComputedBatch, error) {
Expand Down Expand Up @@ -146,7 +150,9 @@ func (executor *batchExecutor) ComputeBatch(context *BatchExecutionContext) (*Co
crossChainTransactions := executor.crossChainProcessors.Local.CreateSyntheticTransactions(messages, stateDB)
executor.crossChainProcessors.Local.ExecuteValueTransfers(transfers, stateDB)

transactionsToProcess := executor.payL1Fees(stateDB, context)
transactionsToProcess, freeTransactions := executor.payL1Fees(stateDB, context)

crossChainTransactions = append(crossChainTransactions, freeTransactions...)

successfulTxs, txReceipts, err := executor.processTransactions(batch, 0, transactionsToProcess, stateDB, context.ChainConfig, false)
if err != nil {
Expand All @@ -165,7 +171,7 @@ func (executor *batchExecutor) ComputeBatch(context *BatchExecutionContext) (*Co
// we need to copy the batch to reset the internal hash cache
copyBatch := *batch
copyBatch.Header.Root = stateDB.IntermediateRoot(false)
copyBatch.Transactions = successfulTxs
copyBatch.Transactions = append(successfulTxs, freeTransactions...)
copyBatch.ResetHash()

if err = executor.populateOutboundCrossChainData(&copyBatch, block, txReceipts); err != nil {
Expand Down Expand Up @@ -259,6 +265,11 @@ func (executor *batchExecutor) CreateGenesisState(
return nil, nil, err
}

var limit uint64 = params.MaxGasLimit
if gasLimit != nil {
limit = gasLimit.Uint64()
}

genesisBatch := &core.Batch{
Header: &common.BatchHeader{
ParentHash: common.L2BatchHash{},
Expand All @@ -272,7 +283,7 @@ func (executor *batchExecutor) CreateGenesisState(
Time: timeNow,
Coinbase: coinbase,
BaseFee: baseFee,
GasLimit: gasLimit.Uint64(), //todo (@siliev) - does the batch header need uint64?
GasLimit: limit, //todo (@siliev) - does the batch header need uint64?
},
Transactions: []*common.L2Tx{},
}
Expand All @@ -283,6 +294,8 @@ func (executor *batchExecutor) CreateGenesisState(
executor.logger.Crit("Could not create message bus deployment transaction", "Error", err)
}

executor.logger.Info("L2 Bus deploy", log.TxKey, deployTx.Hash())

if err = executor.genesis.CommitGenesisState(executor.storage); err != nil {
return nil, nil, fmt.Errorf("could not apply genesis preallocation. Cause: %w", err)
}
Expand Down
1 change: 1 addition & 0 deletions go/enclave/evm/evm_facade.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ func ExecuteObsCall(
return result, err
}

logger.Info("ObsCall - with result ", "gas", result.UsedGas)
return result, nil
}

Expand Down
5 changes: 5 additions & 0 deletions integration/simulation/devnetwork/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ func (n *InMemNodeOperator) createEnclaveContainer() *enclavecontainer.EnclaveCo
hostPort := n.config.PortStart + integration.DefaultHostP2pOffset + n.operatorIdx
hostAddr := fmt.Sprintf("%s:%d", network.Localhost, hostPort)

defaultCfg := config.DefaultEnclaveConfig()

enclaveConfig := &config.EnclaveConfig{
HostID: n.l1Wallet.Address(),
SequencerID: n.config.SequencerID,
Expand All @@ -176,6 +178,9 @@ func (n *InMemNodeOperator) createEnclaveContainer() *enclavecontainer.EnclaveCo
DebugNamespaceEnabled: true,
MaxBatchSize: 1024 * 25,
MaxRollupSize: 1024 * 64,
BaseFee: defaultCfg.BaseFee, // todo @siliev:: fix test transaction builders so this can be different
GasLimit: defaultCfg.GasLimit,
GasPaymentAddress: defaultCfg.GasPaymentAddress,
}
return enclavecontainer.NewEnclaveContainerWithLogger(enclaveConfig, enclaveLogger)
}
Expand Down
2 changes: 1 addition & 1 deletion integration/simulation/network/network_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func createInMemObscuroNode(
MaxBatchSize: 1024 * 25,
MaxRollupSize: 1024 * 64,
BaseFee: big.NewInt(1), // todo @siliev:: fix test transaction builders so this can be different
GasLimit: big.NewInt(1_000_000),
GasLimit: big.NewInt(1_000_000_000),
}

enclaveLogger := testlog.Logger().New(log.NodeIDKey, id, log.CmpKey, log.EnclaveCmp)
Expand Down

0 comments on commit 4500885

Please sign in to comment.