Skip to content

Commit

Permalink
remove costly select (#1583)
Browse files Browse the repository at this point in the history
* remove costly select

* fix
  • Loading branch information
tudor-malene authored Oct 6, 2023
1 parent dc900b6 commit 0c161a9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
16 changes: 3 additions & 13 deletions go/enclave/components/batch_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"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 Down Expand Up @@ -35,8 +33,9 @@ func NewBatchRegistry(storage storage.Storage, logger gethlog.Logger) BatchRegis
headBatch, err := storage.FetchHeadBatch()
if err != nil {
if errors.Is(err, errutil.ErrNotFound) {
headBatchSeq = big.NewInt(int64(common.L2GenesisSeqNo))
headBatchSeq = nil
} else {
logger.Crit("Could not create batch registry", log.ErrKey, err)
return nil
}
} else {
Expand Down Expand Up @@ -79,16 +78,7 @@ func (br *batchRegistry) OnBatchExecuted(batch *core.Batch, receipts types.Recei
}

func (br *batchRegistry) HasGenesisBatch() (bool, error) {
genesisBatchStored := true
_, err := br.storage.FetchHeadBatch()
if err != nil {
if !errors.Is(err, errutil.ErrNotFound) {
return false, fmt.Errorf("could not retrieve current head batch. Cause: %w", err)
}
genesisBatchStored = false
}

return genesisBatchStored, nil
return br.headBatchSeq != nil, nil
}

func (br *batchRegistry) BatchesAfter(batchSeqNo uint64, upToL1Height uint64, rollupLimiter limiters.RollupLimiter) ([]*core.Batch, []*types.Block, error) {
Expand Down
3 changes: 3 additions & 0 deletions go/enclave/nodetype/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ func (s *sequencer) initGenesis(block *common.L1Block) error {

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

func (val *obsValidator) ExecuteStoredBatches() error {
batches, err := val.storage.FetchCanonicalUnexecutedBatches(val.batchRegistry.HeadBatchSeq())
headBatchSeq := val.batchRegistry.HeadBatchSeq()
if headBatchSeq == nil {
headBatchSeq = big.NewInt(int64(common.L2GenesisSeqNo))
}
batches, err := val.storage.FetchCanonicalUnexecutedBatches(headBatchSeq)
if err != nil {
if errors.Is(err, errutil.ErrNotFound) {
return nil
Expand Down

0 comments on commit 0c161a9

Please sign in to comment.