Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into pedro/rollup_producti…
Browse files Browse the repository at this point in the history
…on_based_on_size
  • Loading branch information
otherview committed Sep 22, 2023
2 parents c34fc81 + 07b12fa commit 6a85438
Show file tree
Hide file tree
Showing 26 changed files with 264 additions and 231 deletions.
2 changes: 1 addition & 1 deletion go/config/enclave_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func DefaultEnclaveConfig() *EnclaveConfig {
DebugNamespaceEnabled: false,
MaxBatchSize: 1024 * 25,
MaxRollupSize: 1024 * 64,
GasPaymentAddress: gethcommon.HexToAddress("0xa714Ae85AA66424766ba4Df364EECc43197051A6"),
GasPaymentAddress: gethcommon.HexToAddress("0xd6C9230053f45F873Cb66D8A02439380a37A4fbF"),
BaseFee: new(big.Int).SetUint64(1),
GasLimit: new(big.Int).SetUint64(params.MaxGasLimit / 6),
}
Expand Down
29 changes: 25 additions & 4 deletions go/enclave/components/batch_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package components
import (
"errors"
"fmt"
"math/big"
"sync"

"github.com/obscuronet/go-obscuro/go/common"

"github.com/ethereum/go-ethereum/core/types"
"github.com/obscuronet/go-obscuro/go/enclave/storage"

Expand All @@ -19,20 +22,37 @@ import (
)

type batchRegistry struct {
storage storage.Storage
logger gethlog.Logger
storage storage.Storage
logger gethlog.Logger
headBatchSeq *big.Int // keep track of the last executed batch to optimise db access

batchesCallback func(*core.Batch, types.Receipts)
callbackMutex sync.RWMutex
}

func NewBatchRegistry(storage storage.Storage, logger gethlog.Logger) BatchRegistry {
var headBatchSeq *big.Int
headBatch, err := storage.FetchHeadBatch()
if err != nil {
if errors.Is(err, errutil.ErrNotFound) {
headBatchSeq = big.NewInt(int64(common.L2GenesisSeqNo))
} else {
return nil
}
} else {
headBatchSeq = headBatch.SeqNo()
}
return &batchRegistry{
storage: storage,
logger: logger,
storage: storage,
headBatchSeq: headBatchSeq,
logger: logger,
}
}

func (br *batchRegistry) HeadBatchSeq() *big.Int {
return br.headBatchSeq
}

func (br *batchRegistry) SubscribeForExecutedBatches(callback func(*core.Batch, types.Receipts)) {
br.callbackMutex.Lock()
defer br.callbackMutex.Unlock()
Expand All @@ -52,6 +72,7 @@ func (br *batchRegistry) OnBatchExecuted(batch *core.Batch, receipts types.Recei

defer br.logger.Debug("Sending batch and events", log.BatchHashKey, batch.Hash(), log.DurationKey, measure.NewStopwatch())

br.headBatchSeq = batch.SeqNo()
if br.batchesCallback != nil {
br.batchesCallback(batch, receipts)
}
Expand Down
1 change: 1 addition & 0 deletions go/enclave/components/block_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (bp *l1BlockProcessor) ingestBlock(block *common.L1Block) (*BlockIngestionT
bp.logger.Trace("parent not found",
"blkHeight", block.NumberU64(), log.BlockHashKey, block.Hash(),
"l1HeadHeight", prevL1Head.NumberU64(), "l1HeadHash", prevL1Head.Hash(),
log.ErrKey, err,
)
return nil, errutil.ErrBlockAncestorNotFound
}
Expand Down
2 changes: 2 additions & 0 deletions go/enclave/components/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ type BatchRegistry interface {
// HasGenesisBatch - returns if genesis batch is available yet or not, or error in case
// the function is unable to determine.
HasGenesisBatch() (bool, error)

HeadBatchSeq() *big.Int
}

type RollupProducer interface {
Expand Down
4 changes: 1 addition & 3 deletions go/enclave/enclave.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ func (e *enclaveImpl) SubmitTx(tx common.EncryptedTx) (*responses.RawTx, common.
}

if err = e.service.SubmitTransaction(decryptedTx); err != nil {
e.logger.Warn("Could not submit transaction", log.TxKey, decryptedTx.Hash(), log.ErrKey, err)
e.logger.Debug("Could not submit transaction", log.TxKey, decryptedTx.Hash(), log.ErrKey, err)
return responses.AsEncryptedError(err, vkHandler), nil
}

Expand Down Expand Up @@ -688,8 +688,6 @@ func (e *enclaveImpl) ObsCall(encryptedParams common.EncryptedParamsCall) (*resp
encodedResult = hexutil.Encode(execResult.ReturnData)
}

e.logger.Info("Call result success ", "result", encodedResult)

return responses.AsEncryptedResponse(&encodedResult, vkHandler), nil
}

Expand Down
2 changes: 0 additions & 2 deletions go/enclave/evm/evm_facade.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ func ExecuteObsCall(
noBaseFee := true
if header.BaseFee != nil && header.BaseFee.Cmp(gethcommon.Big0) != 0 && msg.GasPrice.Cmp(gethcommon.Big0) != 0 {
noBaseFee = false
logger.Info("ObsCall - with base fee ", "to", msg.To.Hex())
}

chain, vmCfg, gp := initParams(storage, noBaseFee, nil)
Expand Down Expand Up @@ -186,7 +185,6 @@ func ExecuteObsCall(
return result, err
}

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

Expand Down
2 changes: 1 addition & 1 deletion go/enclave/gas/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (gp *ObscuroGasPool) ForTransaction(tx *types.Transaction) (*gethcore.GasPo
// CalculateL1GasUsed - calculates the gas cost of having a transaction on the l1.
func CalculateL1GasUsed(data []byte, overhead *big.Int) *big.Int {
reducedTxSize := uint64(len(data))
reducedTxSize = (reducedTxSize * 75) / 100
reducedTxSize = (reducedTxSize * 90) / 100
reducedTxSize = reducedTxSize * params.TxDataNonZeroGasEIP2028

l1Gas := new(big.Int).SetUint64(reducedTxSize)
Expand Down
1 change: 0 additions & 1 deletion go/enclave/l2chain/l2_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ func (oc *obscuroChain) ObsCallAtBlock(apiArgs *gethapi.TransactionArgs, blockNu
result, err := evm.ExecuteObsCall(callMsg, blockState, batch.Header, oc.storage, oc.chainConfig, oc.logger)
if err != nil {
// also return the result as the result can be evaluated on some errors like ErrIntrinsicGas
oc.logger.Info("Call failed with error", log.ErrKey, err)
return result, err
}

Expand Down
3 changes: 2 additions & 1 deletion go/enclave/nodetype/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ func (s *sequencer) initGenesis(block *common.L1Block) error {
}

func (s *sequencer) createNewHeadBatch(l1HeadBlock *common.L1Block) error {
headBatch, err := s.storage.FetchHeadBatch()
headBatchSeq := s.batchRegistry.HeadBatchSeq()
headBatch, err := s.storage.FetchBatchBySeqNo(headBatchSeq.Uint64())
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion go/enclave/nodetype/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (val *obsValidator) VerifySequencerSignature(b *core.Batch) error {
}

func (val *obsValidator) ExecuteStoredBatches() error {
batches, err := val.storage.FetchCanonicalUnexecutedBatches()
batches, err := val.storage.FetchCanonicalUnexecutedBatches(val.batchRegistry.HeadBatchSeq())
if err != nil {
if errors.Is(err, errutil.ErrNotFound) {
return nil
Expand Down
39 changes: 39 additions & 0 deletions go/enclave/storage/db_cache.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package storage

import (
"context"

"github.com/eko/gocache/lib/v4/cache"
gethlog "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
"github.com/obscuronet/go-obscuro/go/common/log"
)

func getCachedValue[V any](cache *cache.Cache[[]byte], logger gethlog.Logger, key any, onFailed func(any) (V, error)) (V, error) {
value, err := cache.Get(context.Background(), key)
if err != nil {
// todo metrics for cache misses
b, err := onFailed(key)
if err != nil {
return b, err
}
cacheValue(cache, logger, key, b)
return b, err
}

v := new(V)
err = rlp.DecodeBytes(value, v)
return *v, err
}

func cacheValue(cache *cache.Cache[[]byte], logger gethlog.Logger, key any, v any) {
encoded, err := rlp.EncodeToBytes(v)
if err != nil {
logger.Error("Could not encode value to store in cache", log.ErrKey, err)
return
}
err = cache.Set(context.Background(), key, encoded)
if err != nil {
logger.Error("Could not store value in cache", log.ErrKey, err)
}
}
Loading

0 comments on commit 6a85438

Please sign in to comment.