Skip to content

Commit

Permalink
Resolved PR comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanIliev545 committed Sep 18, 2023
1 parent 6f75ee8 commit d64203e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
6 changes: 3 additions & 3 deletions go/common/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Check failure on line 104 in go/common/headers.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
//BatchHeaders []*BatchHeader

ReOrgs [][]byte `rlp:"optional"` // sparse list of reorged headers - non null only for reorgs.
}
Expand Down
3 changes: 3 additions & 0 deletions go/enclave/components/batch_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 65 in go/enclave/components/batch_executor.go

View workflow job for this annotation

GitHub Actions / lint

`substract` is a misspelling of `subtract` (misspell)
// publishing costs.
func (executor *batchExecutor) payL1Fees(stateDB *state.StateDB, context *BatchExecutionContext) common.L2Transactions {
transactions := make(common.L2Transactions, 0)
block, _ := executor.storage.FetchBlock(context.BlockPtr)
Expand Down
22 changes: 11 additions & 11 deletions go/enclave/components/rollup_compression.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions go/enclave/gas/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions go/enclave/gas/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -22,13 +24,17 @@ 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.

Check failure on line 28 in go/enclave/gas/oracle.go

View workflow job for this annotation

GitHub Actions / lint

`mechancis` is a misspelling of `mechanics` (misspell)
// 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 {
o.baseFee = blockBaseFee
}
}

// 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 {
Expand Down

0 comments on commit d64203e

Please sign in to comment.