From ad6cf2c737b7107c337b9ed6187b7b0a0f96187c Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Wed, 18 Dec 2024 13:38:22 +0200 Subject: [PATCH] optimize mutexes and increase batch size --- go/config/defaults/0-base-config.yaml | 2 +- go/enclave/enclave_admin_service.go | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/go/config/defaults/0-base-config.yaml b/go/config/defaults/0-base-config.yaml index 5dad19fb8..285346e65 100644 --- a/go/config/defaults/0-base-config.yaml +++ b/go/config/defaults/0-base-config.yaml @@ -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 diff --git a/go/enclave/enclave_admin_service.go b/go/enclave/enclave_admin_service.go index fc6d26b91..b635ebec8 100644 --- a/go/enclave/enclave_admin_service.go +++ b/go/enclave/enclave_admin_service.go @@ -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 @@ -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, @@ -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()) @@ -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()) @@ -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 { @@ -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"))