Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
danwt committed Dec 16, 2024
1 parent cd06688 commit f5baf99
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion block/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (m *Manager) OnReceivedBlock(event pubsub.Message) {
// gossipBlock sends created blocks by the sequencer to full-nodes using P2P gossipSub
func (m *Manager) gossipBlock(ctx context.Context, block types.Block, commit types.Commit) error {
m.logger.Info("Gossipping block", "height", block.Header.Height)
commit = *m.fraudBlockAndCommit(dofraud.Gossip, block.Header.Height, &block)
m.fraudBlockAndCommit(dofraud.Gossip, block.Header.Height, &block, &commit)
gossipedBlock := p2p.BlockData{Block: block, Commit: commit}
gossipedBlockBytes, err := gossipedBlock.MarshalBinary()
if err != nil {
Expand Down
18 changes: 10 additions & 8 deletions block/produce.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ func (m *Manager) produceBlock(opts ProduceBlockOptions) (*types.Block, *types.C

// dequeue consensus messages for the new sequencers while creating a new block
block = m.Executor.CreateBlock(newHeight, lastCommit, lastHeaderHash, proposerHashForBlock, m.State, maxBlockDataSize)
m.fraudBlockAndCommit(dofraud.Produce, newHeight, block)

// this cannot happen if there are any sequencer set updates
// AllowEmpty should be always true in this case
Expand All @@ -251,6 +250,7 @@ func (m *Manager) produceBlock(opts ProduceBlockOptions) (*types.Block, *types.C
if err != nil {
return nil, nil, fmt.Errorf("create commit: %w: %w", err, ErrNonRecoverable)
}
m.fraudBlockAndCommit(dofraud.Produce, newHeight, block, commit)

m.logger.Info("Block created.", "height", newHeight, "num_tx", len(block.Data.Txs), "size", block.SizeBytes()+commit.SizeBytes())
types.RollappBlockSizeBytesGauge.Set(float64(len(block.Data.Txs)))
Expand Down Expand Up @@ -352,12 +352,14 @@ func getHeaderHashAndCommit(store store.Store, height uint64) ([32]byte, *types.
return lastBlock.Header.Hash(), lastCommit, nil
}

// modifies the block, returns new commit
func (m *Manager) fraudBlockAndCommit(variant dofraud.FraudVariant, h uint64, b *types.Block) *types.Commit {
m.fraudSim.Apply(m.logger, h, variant, b)
comm, err := m.createCommit(b)
if err != nil {
m.logger.Error("Fraud block, create commit.", "err", err)
// if a fraud is specified, apply it (modify block, commit)
func (m *Manager) fraudBlockAndCommit(variant dofraud.FraudVariant, h uint64, b *types.Block, c *types.Commit) {
if m.fraudSim.Apply(m.logger, h, variant, b) {
comm, err := m.createCommit(b)
if err != nil {
m.logger.Error("Fraud block, create commit.", "err", err)
} else {
*c = *comm
}
}
return comm
}
14 changes: 6 additions & 8 deletions block/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ func (m *Manager) SubmitLoop(ctx context.Context,
func SubmitLoopInner(
ctx context.Context,
logger types.Logger,
bytesProduced chan int, // a channel of block and commit bytes produced
maxSkewTime time.Duration, // max time between last submitted block and last produced block allowed. if this threshold is reached block production is stopped.
bytesProduced chan int, // a channel of block and commit bytes produced
maxSkewTime time.Duration, // max time between last submitted block and last produced block allowed. if this threshold is reached block production is stopped.
unsubmittedBlocksNum func() uint64, // func that returns the amount of non-submitted blocks
unsubmittedBlocksBytes func() int, // func that returns bytes from non-submitted blocks
unsubmittedBlocksBytes func() int, // func that returns bytes from non-submitted blocks
batchSkewTime func() time.Duration, // func that returns measured time between last submitted block and last produced block
maxBatchSubmitTime time.Duration, // max time to allow between batches
maxBatchSubmitBytes uint64, // max size of serialised batch in bytes
maxBatchSubmitTime time.Duration, // max time to allow between batches
maxBatchSubmitBytes uint64, // max size of serialised batch in bytes
createAndSubmitBatch func(maxSizeBytes uint64) (bytes uint64, err error),
) error {
eg, ctx := errgroup.WithContext(ctx)
Expand Down Expand Up @@ -329,10 +329,8 @@ func UpdateBatchSubmissionGauges(skewBytes uint64, skewBlocks uint64, skewTime t
types.RollappPendingSubmissionsSkewTimeMinutes.Set(float64(skewTime.Minutes()))
}

// (if frauds are specified)
func (m *Manager) applyFraudsToBatch(batch *types.Batch) {
for i, block := range batch.Blocks {
comm := m.fraudBlockAndCommit(dofraud.DA, block.Header.Height, block)
batch.Commits[i] = comm
m.fraudBlockAndCommit(dofraud.DA, block.Header.Height, block, batch.Commits[i])
}
}
6 changes: 4 additions & 2 deletions dofraud/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ func (k key) String() string {
return fmt.Sprintf("%d:%d", k.height, k.variant)
}

func (f *Frauds) Apply(log types.Logger, height uint64, fraudVariant FraudVariant, b *types.Block) {
// apply any loaded frauds, no-op if none
func (f *Frauds) Apply(log types.Logger, height uint64, fraudVariant FraudVariant, b *types.Block) bool {
cmd, ok := f.frauds[key{height, fraudVariant}.String()]
if !ok {
return
return false
}

for _, fraud := range cmd.ts {
Expand Down Expand Up @@ -102,4 +103,5 @@ func (f *Frauds) Apply(log types.Logger, height uint64, fraudVariant FraudVarian
}

log.Info("Applied fraud.", "height", height, "variant", fraudVariant, "types", cmd.ts)
return true
}

0 comments on commit f5baf99

Please sign in to comment.