From d64203e683963ee837a0fea32a564be1351a666a Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Mon, 18 Sep 2023 14:28:47 +0300 Subject: [PATCH] Resolved PR comments. --- go/common/headers.go | 6 +++--- go/enclave/components/batch_executor.go | 3 +++ go/enclave/components/rollup_compression.go | 22 ++++++++++----------- go/enclave/gas/gas.go | 1 + go/enclave/gas/oracle.go | 6 ++++++ 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/go/common/headers.go b/go/common/headers.go index 6cb6f6af33..b7f2a6492e 100644 --- a/go/common/headers.go +++ b/go/common/headers.go @@ -42,7 +42,7 @@ type BatchHeader struct { CrossChainMessages []MessageBus.StructsCrossChainMessage `json:"crossChainMessages"` LatestInboundCrossChainHash common.Hash `json:"inboundCrossChainHash"` // The block hash of the latest block that has been scanned for cross chain messages. LatestInboundCrossChainHeight *big.Int `json:"inboundCrossChainHeight"` // The block height of the latest block that has been scanned for cross chain messages. - TransfersTree common.Hash `json:"transfersTree"` + TransfersTree common.Hash `json:"transfersTree"` // This is a merkle tree of all of the outbound value transfers for the MainNet } // MarshalJSON custom marshals the BatchHeader into a json @@ -101,8 +101,8 @@ type CalldataRollupHeader struct { L1HeightDeltas [][]byte // delta of the block height. Stored as a byte array because rlp can't encode negative numbers // these fields are for debugging the compression. Uncomment if there are issues - BatchHashes []L2BatchHash - BatchHeaders []*BatchHeader + //BatchHashes []L2BatchHash + //BatchHeaders []*BatchHeader ReOrgs [][]byte `rlp:"optional"` // sparse list of reorged headers - non null only for reorgs. } diff --git a/go/enclave/components/batch_executor.go b/go/enclave/components/batch_executor.go index 439cf0a13b..700408481b 100644 --- a/go/enclave/components/batch_executor.go +++ b/go/enclave/components/batch_executor.go @@ -61,6 +61,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 { transactions := make(common.L2Transactions, 0) block, _ := executor.storage.FetchBlock(context.BlockPtr) diff --git a/go/enclave/components/rollup_compression.go b/go/enclave/components/rollup_compression.go index f86ef0e89c..6bc62bffe2 100644 --- a/go/enclave/components/rollup_compression.go +++ b/go/enclave/components/rollup_compression.go @@ -243,10 +243,10 @@ func (rc *RollupCompression) createRollupHeader(batches []*core.Batch) (*common. BatchTimeDeltas: timeDeltasBA, ReOrgs: reorgsBA, L1HeightDeltas: l1DeltasBA, - BatchHashes: batchHashes, - BatchHeaders: batchHeaders, - Coinbase: batches[0].Header.Coinbase, - BaseFee: batches[0].Header.BaseFee, + // BatchHashes: batchHashes, + // BatchHeaders: batchHeaders, + Coinbase: batches[0].Header.Coinbase, + BaseFee: batches[0].Header.BaseFee, } return calldataRollupHeader, nil @@ -367,7 +367,7 @@ func (rc *RollupCompression) executeAndSaveIncompleteBatches(calldataRollupHeade } } - for i, incompleteBatch := range incompleteBatches { + for _, incompleteBatch := range incompleteBatches { // check whether the batch is already stored in the database b, err := rc.storage.FetchBatchBySeqNo(incompleteBatch.seqNo.Uint64()) if err == nil { @@ -386,10 +386,10 @@ func (rc *RollupCompression) executeAndSaveIncompleteBatches(calldataRollupHeade return err } // Sanity check - uncomment when debugging - if genBatch.Hash() != calldataRollupHeader.BatchHashes[i] { + /*if genBatch.Hash() != calldataRollupHeader.BatchHashes[i] { rc.logger.Info(fmt.Sprintf("Good %+v \n Calc %+v", calldataRollupHeader.BatchHeaders[i], genBatch.Header)) rc.logger.Crit("Rollup decompression failure. The check hashes don't match") - } + }*/ err = rc.storage.StoreBatch(genBatch) if err != nil { @@ -429,10 +429,10 @@ func (rc *RollupCompression) executeAndSaveIncompleteBatches(calldataRollupHeade return err } // Sanity check - uncomment when debugging - if computedBatch.Batch.Hash() != calldataRollupHeader.BatchHashes[i] { - rc.logger.Info(fmt.Sprintf("Good %+v\nCalc %+v", calldataRollupHeader.BatchHeaders[i], computedBatch.Batch.Header)) - rc.logger.Crit("Rollup decompression failure. The check hashes don't match") - } + /* if computedBatch.Batch.Hash() != calldataRollupHeader.BatchHashes[i] { + rc.logger.Info(fmt.Sprintf("Good %+v\nCalc %+v", calldataRollupHeader.BatchHeaders[i], computedBatch.Batch.Header)) + rc.logger.Crit("Rollup decompression failure. The check hashes don't match") + }*/ if _, err := computedBatch.Commit(true); err != nil { return fmt.Errorf("cannot commit stateDB for incoming valid batch seq=%d. Cause: %w", incompleteBatch.seqNo, err) diff --git a/go/enclave/gas/gas.go b/go/enclave/gas/gas.go index eb160fd9a4..771e7e3aa0 100644 --- a/go/enclave/gas/gas.go +++ b/go/enclave/gas/gas.go @@ -31,6 +31,7 @@ func (gp *ObscuroGasPool) ForTransaction(tx *types.Transaction) (*gethcore.GasPo return &gPool, nil } +// CalculateL1GasUsed - calculates the gas cost of having a transaction on the l1. func CalculateL1GasUsed(data []byte, overhead *big.Int) *big.Int { zeroes, ones := zeroesAndOnes(data) zeroesGas := zeroes * params.TxDataZeroGas diff --git a/go/enclave/gas/oracle.go b/go/enclave/gas/oracle.go index ac481c7eac..e9fe44bc8c 100644 --- a/go/enclave/gas/oracle.go +++ b/go/enclave/gas/oracle.go @@ -7,6 +7,8 @@ import ( "github.com/ethereum/go-ethereum/rlp" ) +// Oracle - the interface for the future precompiled gas oracle contract +// which will expose necessary l1 information. type Oracle interface { ProcessL1Block(block *types.Block) GetGasCostForTx(tx *types.Transaction, block *types.Block) (*big.Int, error) @@ -22,6 +24,9 @@ func NewGasOracle() Oracle { } } +// ProcessL1Block - should be used to update the gas oracle. Currently does not really +// fit into phase 1 gas mechancis as the information needs to be available per block. +// would be fixed when this becomes a smart contract using the stateDB func (o *oracle) ProcessL1Block(block *types.Block) { blockBaseFee := block.BaseFee() if blockBaseFee != nil { @@ -29,6 +34,7 @@ func (o *oracle) ProcessL1Block(block *types.Block) { } } +// GetGasCostForTx - Returns the expected l1 gas cost for a transaction at a given l1 block. func (o *oracle) GetGasCostForTx(tx *types.Transaction, block *types.Block) (*big.Int, error) { encodedTx, err := rlp.EncodeToBytes(tx) if err != nil {