-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance fixes - speed and memory #1567
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,47 +13,30 @@ import ( | |
"github.com/obscuronet/go-obscuro/contracts/generated/MessageBus" | ||
|
||
"github.com/obscuronet/go-obscuro/go/common" | ||
"github.com/obscuronet/go-obscuro/go/enclave/crypto" | ||
"github.com/obscuronet/go-obscuro/go/enclave/limiters" | ||
|
||
gethcommon "github.com/ethereum/go-ethereum/common" | ||
"github.com/obscuronet/go-obscuro/go/enclave/core" | ||
) | ||
|
||
// rollupProducerImpl encapsulates the logic of decoding rollup transactions submitted to the L1 and resolving them | ||
// to rollups that the enclave can process. | ||
type rollupProducerImpl struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there were a bunch of unused fields, and the comment was out of date |
||
// TransactionBlobCrypto- This contains the required properties to encrypt rollups. | ||
TransactionBlobCrypto crypto.DataEncryptionService | ||
|
||
ObscuroChainID int64 | ||
EthereumChainID int64 | ||
|
||
sequencerID gethcommon.Address | ||
|
||
logger gethlog.Logger | ||
|
||
storage storage.Storage | ||
|
||
batchRegistry BatchRegistry | ||
blockProcessor L1BlockProcessor | ||
sequencerID gethcommon.Address | ||
storage storage.Storage | ||
batchRegistry BatchRegistry | ||
logger gethlog.Logger | ||
} | ||
|
||
func NewRollupProducer(sequencerID gethcommon.Address, transactionBlobCrypto crypto.DataEncryptionService, obscuroChainID int64, ethereumChainID int64, storage storage.Storage, batchRegistry BatchRegistry, blockProcessor L1BlockProcessor, logger gethlog.Logger) RollupProducer { | ||
func NewRollupProducer(sequencerID gethcommon.Address, storage storage.Storage, batchRegistry BatchRegistry, logger gethlog.Logger) RollupProducer { | ||
return &rollupProducerImpl{ | ||
TransactionBlobCrypto: transactionBlobCrypto, | ||
ObscuroChainID: obscuroChainID, | ||
EthereumChainID: ethereumChainID, | ||
sequencerID: sequencerID, | ||
logger: logger, | ||
batchRegistry: batchRegistry, | ||
blockProcessor: blockProcessor, | ||
storage: storage, | ||
sequencerID: sequencerID, | ||
logger: logger, | ||
batchRegistry: batchRegistry, | ||
storage: storage, | ||
} | ||
} | ||
|
||
func (re *rollupProducerImpl) CreateRollup(fromBatchNo uint64, upToL1Height uint64, limiter limiters.RollupLimiter) (*core.Rollup, error) { | ||
batches, err := re.batchRegistry.BatchesAfter(fromBatchNo, upToL1Height, limiter) | ||
func (re *rollupProducerImpl) CreateInternalRollup(fromBatchNo uint64, upToL1Height uint64, limiter limiters.RollupLimiter) (*core.Rollup, error) { | ||
batches, blocks, err := re.batchRegistry.BatchesAfter(fromBatchNo, upToL1Height, limiter) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not fetch 'from' batch (seqNo=%d) for rollup: %w", fromBatchNo, err) | ||
} | ||
|
@@ -68,17 +51,6 @@ func (re *rollupProducerImpl) CreateRollup(fromBatchNo uint64, upToL1Height uint | |
if err != nil { | ||
return nil, err | ||
} | ||
newRollup := re.createNextRollup(batches, block) | ||
|
||
re.logger.Info(fmt.Sprintf("Created new rollup %s with %d batches. From %d to %d", newRollup.Hash(), len(newRollup.Batches), batches[0].SeqNo(), batches[len(batches)-1].SeqNo())) | ||
|
||
return newRollup, nil | ||
} | ||
|
||
// createNextRollup - based on a previous rollup and batches will create a new rollup that encapsulate the state | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. outdated comment, and the method had no clear responsibility |
||
// transition from the old rollup to the new one's head batch. | ||
func (re *rollupProducerImpl) createNextRollup(batches []*core.Batch, block *types.Block) *core.Rollup { | ||
lastBatch := batches[len(batches)-1] | ||
|
||
rh := common.RollupHeader{} | ||
rh.CompressionL1Head = block.Hash() | ||
|
@@ -89,9 +61,21 @@ func (re *rollupProducerImpl) createNextRollup(batches []*core.Batch, block *typ | |
rh.CrossChainMessages = append(rh.CrossChainMessages, b.Header.CrossChainMessages...) | ||
} | ||
|
||
lastBatch := batches[len(batches)-1] | ||
rh.LastBatchSeqNo = lastBatch.SeqNo().Uint64() | ||
return &core.Rollup{ | ||
|
||
blockMap := map[common.L1BlockHash]*types.Block{} | ||
for _, b := range blocks { | ||
blockMap[b.Hash()] = b | ||
} | ||
|
||
newRollup := &core.Rollup{ | ||
Header: &rh, | ||
Blocks: blockMap, | ||
Batches: batches, | ||
} | ||
|
||
re.logger.Info(fmt.Sprintf("Created new rollup %s with %d batches. From %d to %d", newRollup.Hash(), len(newRollup.Batches), batches[0].SeqNo(), rh.LastBatchSeqNo)) | ||
|
||
return newRollup, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,17 +259,22 @@ func (s *sequencer) CreateRollup(lastBatchNo uint64) (*common.ExtRollup, error) | |
return nil, err | ||
} | ||
upToL1Height := currentL1Head.NumberU64() - RollupDelay | ||
rollup, err := s.rollupProducer.CreateRollup(lastBatchNo, upToL1Height, rollupLimiter) | ||
rollup, err := s.rollupProducer.CreateInternalRollup(lastBatchNo, upToL1Height, rollupLimiter) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
extRollup, err := s.rollupCompression.CreateExtRollup(rollup) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to compress rollup: %w", err) | ||
} | ||
|
||
// todo - double-check that this signing approach is secure, and it properly includes the entire payload | ||
if err := s.signRollup(rollup); err != nil { | ||
if err := s.signRollup(extRollup); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes more logical sense to sign over the external rollup |
||
return nil, fmt.Errorf("failed to sign created rollup: %w", err) | ||
} | ||
|
||
return s.rollupCompression.CreateExtRollup(rollup) | ||
return extRollup, nil | ||
} | ||
|
||
func (s *sequencer) duplicateBatches(l1Head *types.Block, nonCanonicalL1Path []common.L1BlockHash) error { | ||
|
@@ -358,7 +363,7 @@ func (s *sequencer) signBatch(batch *core.Batch) error { | |
return nil | ||
} | ||
|
||
func (s *sequencer) signRollup(rollup *core.Rollup) error { | ||
func (s *sequencer) signRollup(rollup *common.ExtRollup) error { | ||
var err error | ||
h := rollup.Header.Hash() | ||
rollup.Header.R, rollup.Header.S, err = ecdsa.Sign(rand.Reader, s.enclavePrivateKey, h[:]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should update the comment on this probably