Skip to content

Commit

Permalink
optimize mutexes and increase batch size
Browse files Browse the repository at this point in the history
  • Loading branch information
tudor-malene committed Dec 18, 2024
1 parent 6328e9a commit ad6cf2c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go/config/defaults/0-base-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ network:
batch:
interval: 1s
maxInterval: 1s # if this is greater than batch.interval then we make batches more slowly when there are no transactions
maxSize: 45000 # around 45kb - around 200 transactions / batch
maxSize: 61440 # 60kb - around 300 transactions / batch
rollup:
interval: 5s
maxInterval: 10m # rollups will be produced after this time even if the data blob is not full
Expand Down
21 changes: 12 additions & 9 deletions go/enclave/enclave_admin_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import (

type enclaveAdminService struct {
config *enclaveconfig.EnclaveConfig
mainMutex sync.Mutex // serialises all data ingestion or creation to avoid weird races
mainMutex sync.Mutex // locks the admin operations
dataInMutex sync.RWMutex // controls access to data ingestion
logger gethlog.Logger
l1BlockProcessor components.L1BlockProcessor
validatorService nodetype.Validator
Expand Down Expand Up @@ -92,6 +93,7 @@ func NewEnclaveAdminAPI(config *enclaveconfig.EnclaveConfig, storage storage.Sto
eas := &enclaveAdminService{
config: config,
mainMutex: sync.Mutex{},
dataInMutex: sync.RWMutex{},
logger: logger,
l1BlockProcessor: blockProcessor,
service: validatorService,
Expand Down Expand Up @@ -176,8 +178,8 @@ func (e *enclaveAdminService) MakeActive() common.SystemError {

// SubmitL1Block is used to update the enclave with an additional L1 block.
func (e *enclaveAdminService) SubmitL1Block(ctx context.Context, blockHeader *types.Header, receipts []*common.TxAndReceiptAndBlobs) (*common.BlockSubmissionResponse, common.SystemError) {
e.mainMutex.Lock()
defer e.mainMutex.Unlock()
e.dataInMutex.Lock()
defer e.dataInMutex.Unlock()

e.logger.Info("SubmitL1Block", log.BlockHeightKey, blockHeader.Number, log.BlockHashKey, blockHeader.Hash())

Expand Down Expand Up @@ -237,8 +239,8 @@ func (e *enclaveAdminService) SubmitBatch(ctx context.Context, extBatch *common.
return err
}

e.mainMutex.Lock()
defer e.mainMutex.Unlock()
e.dataInMutex.Lock()
defer e.dataInMutex.Unlock()

// if the signature is valid, then store the batch together with the converted hash
err = e.storage.StoreBatch(ctx, batch, convertedHeader.Hash())
Expand All @@ -261,8 +263,8 @@ func (e *enclaveAdminService) CreateBatch(ctx context.Context, skipBatchIfEmpty

defer core.LogMethodDuration(e.logger, measure.NewStopwatch(), "CreateBatch call ended")

e.mainMutex.Lock()
defer e.mainMutex.Unlock()
e.dataInMutex.RLock()
defer e.dataInMutex.RUnlock()

err := e.sequencer().CreateBatch(ctx, skipBatchIfEmpty)
if err != nil {
Expand All @@ -278,8 +280,9 @@ func (e *enclaveAdminService) CreateRollup(ctx context.Context, fromSeqNo uint64
}
defer core.LogMethodDuration(e.logger, measure.NewStopwatch(), "CreateRollup call ended")

e.mainMutex.Lock()
defer e.mainMutex.Unlock()
// allow the simultaneous production of rollups and batches
e.dataInMutex.RLock()
defer e.dataInMutex.RUnlock()

if e.registry.HeadBatchSeq() == nil {
return nil, responses.ToInternalError(fmt.Errorf("not initialised yet"))
Expand Down

0 comments on commit ad6cf2c

Please sign in to comment.