Skip to content

Commit

Permalink
aesthetic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Dec 17, 2024
1 parent f91febd commit 142ba87
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 63 deletions.
124 changes: 62 additions & 62 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1081,105 +1081,105 @@ func (b *Blockchain) verifyAgainstReference(block *core.Block,
return nil
}

func (b *Blockchain) validateStateDiff(shadowStateUpdate, pendingStateUpdate *core.StateUpdate) error {
_, diffFound := pendingStateUpdate.StateDiff.Diff(shadowStateUpdate.StateDiff, "sequencer", "sepolia")
func (b *Blockchain) validateStateDiff(refStateUpdate, pendingStateUpdate *core.StateUpdate) error {
_, diffFound := pendingStateUpdate.StateDiff.Diff(refStateUpdate.StateDiff, "sequencer", "sepolia")
if diffFound {
// Todo: make format nicely
return fmt.Errorf("state diff validation failed")
}

Check warning on line 1089 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1087-L1089

Added lines #L1087 - L1089 were not covered by tests
return nil
}

func (b *Blockchain) validateCommitments(shadowBlock *core.Block, shadowStateUpdate *core.StateUpdate,
sequenceCommitments *core.BlockCommitments,
func (b *Blockchain) validateCommitments(refBlock *core.Block, refStateUpdate *core.StateUpdate,
sequencedCommitments *core.BlockCommitments,
) error {
_, shadowCommitments, err := core.BlockHash(shadowBlock, shadowStateUpdate.StateDiff, b.network, nil)
_, refCommitments, err := core.BlockHash(refBlock, refStateUpdate.StateDiff, b.network, nil)
if err != nil {
return fmt.Errorf("failed to compute the shadow commitments %s", err)
return fmt.Errorf("failed to compute the reference commitments %s", err)
}

Check warning on line 1099 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1098-L1099

Added lines #L1098 - L1099 were not covered by tests
blockVer, err := core.ParseBlockVersion(shadowBlock.ProtocolVersion)
blockVer, err := core.ParseBlockVersion(refBlock.ProtocolVersion)
if err != nil {
return err
}

Check warning on line 1103 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1102-L1103

Added lines #L1102 - L1103 were not covered by tests
if blockVer.LessThan(semver.MustParse("0.13.2")) {
// receipt commitment isn't needed for pre 0.13.2 blocks. see post07Hash().
shadowCommitments.ReceiptCommitment = nil
refCommitments.ReceiptCommitment = nil
}

if !shadowCommitments.TransactionCommitment.Equal(sequenceCommitments.TransactionCommitment) {
return fmt.Errorf("transaction commitment mismatch: shadow commitment %v, sequence commitment %v",
shadowCommitments.TransactionCommitment, sequenceCommitments.TransactionCommitment)
if !refCommitments.TransactionCommitment.Equal(sequencedCommitments.TransactionCommitment) {
return fmt.Errorf("transaction commitment mismatch: reference commitment %v, sequenced commitment %v",
refCommitments.TransactionCommitment, sequencedCommitments.TransactionCommitment)
}

Check warning on line 1112 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1110-L1112

Added lines #L1110 - L1112 were not covered by tests
if !shadowCommitments.EventCommitment.Equal(sequenceCommitments.EventCommitment) {
return fmt.Errorf("event commitment mismatch: shadow commitment %v, sequence commitment %v",
shadowCommitments.EventCommitment, sequenceCommitments.EventCommitment)
if !refCommitments.EventCommitment.Equal(sequencedCommitments.EventCommitment) {
return fmt.Errorf("event commitment mismatch: reference commitment %v, sequenced commitment %v",
refCommitments.EventCommitment, sequencedCommitments.EventCommitment)
}

Check warning on line 1116 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1114-L1116

Added lines #L1114 - L1116 were not covered by tests
if shadowCommitments.ReceiptCommitment != nil && !shadowCommitments.ReceiptCommitment.Equal(sequenceCommitments.ReceiptCommitment) {
return fmt.Errorf("receipt commitment mismatch: shadow commitment %v, sequence commitment %v",
shadowCommitments.ReceiptCommitment, sequenceCommitments.ReceiptCommitment)
if refCommitments.ReceiptCommitment != nil && !refCommitments.ReceiptCommitment.Equal(sequencedCommitments.ReceiptCommitment) {
return fmt.Errorf("receipt commitment mismatch: reference commitment %v, sequenced commitment %v",
refCommitments.ReceiptCommitment, sequencedCommitments.ReceiptCommitment)
}

Check warning on line 1120 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1118-L1120

Added lines #L1118 - L1120 were not covered by tests
if shadowCommitments.StateDiffCommitment != nil && !shadowCommitments.StateDiffCommitment.Equal(sequenceCommitments.StateDiffCommitment) {
return fmt.Errorf("state diff commitment mismatch: shadow commitment %v, sequence commitment %v",
shadowCommitments.StateDiffCommitment, sequenceCommitments.StateDiffCommitment)
if refCommitments.StateDiffCommitment != nil && !refCommitments.StateDiffCommitment.Equal(sequencedCommitments.StateDiffCommitment) {
return fmt.Errorf("state diff commitment mismatch: reference commitment %v, sequenced commitment %v",
refCommitments.StateDiffCommitment, sequencedCommitments.StateDiffCommitment)
}

Check warning on line 1124 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1122-L1124

Added lines #L1122 - L1124 were not covered by tests
return nil
}

func (b *Blockchain) validateHeader(shadowHeader, sequenceHeader *core.Header) error {
if !shadowHeader.ParentHash.Equal(sequenceHeader.ParentHash) {
return fmt.Errorf("parent hash mismatch: shadowHeader parent hash %v, sequenceHeader parent hash %v",
shadowHeader.ParentHash, sequenceHeader.ParentHash)
func (b *Blockchain) validateHeader(refHeader, sequenceHeader *core.Header) error {
if !refHeader.ParentHash.Equal(sequenceHeader.ParentHash) {
return fmt.Errorf("parent hash mismatch: reference header parent hash %v, sequenced header parent hash %v",
refHeader.ParentHash, sequenceHeader.ParentHash)
}

Check warning on line 1132 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1130-L1132

Added lines #L1130 - L1132 were not covered by tests
if shadowHeader.Number != sequenceHeader.Number {
return fmt.Errorf("block number mismatch: shadowHeader number %v, sequenceHeader number %v",
shadowHeader.Number, sequenceHeader.Number)
if refHeader.Number != sequenceHeader.Number {
return fmt.Errorf("block number mismatch: reference header number %v, sequenced header number %v",
refHeader.Number, sequenceHeader.Number)
}

Check warning on line 1136 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1134-L1136

Added lines #L1134 - L1136 were not covered by tests
if !shadowHeader.SequencerAddress.Equal(sequenceHeader.SequencerAddress) {
return fmt.Errorf("sequencer address mismatch: shadowHeader sequencer address %v, sequenceHeader sequencer address %v",
shadowHeader.SequencerAddress, sequenceHeader.SequencerAddress)
if !refHeader.SequencerAddress.Equal(sequenceHeader.SequencerAddress) {
return fmt.Errorf("sequencer address mismatch: reference header sequencer address %v, sequenced header sequencer address %v",
refHeader.SequencerAddress, sequenceHeader.SequencerAddress)
}

Check warning on line 1140 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1138-L1140

Added lines #L1138 - L1140 were not covered by tests
if shadowHeader.TransactionCount != sequenceHeader.TransactionCount {
return fmt.Errorf("transaction count mismatch: shadowHeader transaction count %v, sequenceHeader transaction count %v",
shadowHeader.TransactionCount, sequenceHeader.TransactionCount)
if refHeader.TransactionCount != sequenceHeader.TransactionCount {
return fmt.Errorf("transaction count mismatch: reference header transaction count %v, sequenced header transaction count %v",
refHeader.TransactionCount, sequenceHeader.TransactionCount)
}

Check warning on line 1144 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1142-L1144

Added lines #L1142 - L1144 were not covered by tests
if shadowHeader.EventCount != sequenceHeader.EventCount {
return fmt.Errorf("event count mismatch: shadowHeader event count %v, sequenceHeader event count %v",
shadowHeader.EventCount, sequenceHeader.EventCount)
if refHeader.EventCount != sequenceHeader.EventCount {
return fmt.Errorf("event count mismatch: reference header event count %v, sequenced header event count %v",
refHeader.EventCount, sequenceHeader.EventCount)
}

Check warning on line 1148 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1146-L1148

Added lines #L1146 - L1148 were not covered by tests
if shadowHeader.Timestamp != sequenceHeader.Timestamp {
return fmt.Errorf("timestamp mismatch: shadowHeader timestamp %v, sequenceHeader timestamp %v",
shadowHeader.Timestamp, sequenceHeader.Timestamp)
if refHeader.Timestamp != sequenceHeader.Timestamp {
return fmt.Errorf("timestamp mismatch: reference header timestamp %v, sequenced header timestamp %v",
refHeader.Timestamp, sequenceHeader.Timestamp)
}

Check warning on line 1152 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1150-L1152

Added lines #L1150 - L1152 were not covered by tests
if shadowHeader.ProtocolVersion != sequenceHeader.ProtocolVersion {
return fmt.Errorf("protocol version mismatch: shadowHeader protocol version %v, sequenceHeader protocol version %v",
shadowHeader.ProtocolVersion, sequenceHeader.ProtocolVersion)
if refHeader.ProtocolVersion != sequenceHeader.ProtocolVersion {
return fmt.Errorf("protocol version mismatch: reference header protocol version %v, sequenced header protocol version %v",
refHeader.ProtocolVersion, sequenceHeader.ProtocolVersion)
}

Check warning on line 1156 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1154-L1156

Added lines #L1154 - L1156 were not covered by tests
if !shadowHeader.GasPrice.Equal(sequenceHeader.GasPrice) {
return fmt.Errorf("gas price mismatch: shadowHeader gas price %v, sequenceHeader gas price %v",
shadowHeader.GasPrice, sequenceHeader.GasPrice)
if !refHeader.GasPrice.Equal(sequenceHeader.GasPrice) {
return fmt.Errorf("gas price mismatch: reference header gas price %v, sequenced header gas price %v",
refHeader.GasPrice, sequenceHeader.GasPrice)
}

Check warning on line 1160 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1158-L1160

Added lines #L1158 - L1160 were not covered by tests
if !shadowHeader.GasPriceSTRK.Equal(sequenceHeader.GasPriceSTRK) {
return fmt.Errorf("gas price STRK mismatch: shadowHeader gas price STRK %v, sequenceHeader gas price STRK %v",
shadowHeader.GasPriceSTRK, sequenceHeader.GasPriceSTRK)
if !refHeader.GasPriceSTRK.Equal(sequenceHeader.GasPriceSTRK) {
return fmt.Errorf("gas price STRK mismatch: reference header gas price STRK %v, sequenced header gas price STRK %v",
refHeader.GasPriceSTRK, sequenceHeader.GasPriceSTRK)
}

Check warning on line 1164 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1162-L1164

Added lines #L1162 - L1164 were not covered by tests
if shadowHeader.L1DAMode != sequenceHeader.L1DAMode {
return fmt.Errorf("L1 data availability mode mismatch: shadowHeader L1DAMode %v, sequenceHeader L1DAMode %v",
shadowHeader.L1DAMode, sequenceHeader.L1DAMode)
if refHeader.L1DAMode != sequenceHeader.L1DAMode {
return fmt.Errorf("L1 data availability mode mismatch: reference header L1DAMode %v, sequenced header L1DAMode %v",
refHeader.L1DAMode, sequenceHeader.L1DAMode)
}

Check warning on line 1168 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1166-L1168

Added lines #L1166 - L1168 were not covered by tests
if !shadowHeader.L1DataGasPrice.PriceInFri.Equal(sequenceHeader.L1DataGasPrice.PriceInFri) {
return fmt.Errorf("L1 data gas PriceInFri mismatch: shadowHeader L1DataGasPrice %v, sequenceHeader L1DataGasPrice %v",
shadowHeader.L1DataGasPrice, sequenceHeader.L1DataGasPrice)
if !refHeader.L1DataGasPrice.PriceInFri.Equal(sequenceHeader.L1DataGasPrice.PriceInFri) {
return fmt.Errorf("L1 data gas PriceInFri mismatch: reference header L1DataGasPrice %v, sequenced header L1DataGasPrice %v",
refHeader.L1DataGasPrice, sequenceHeader.L1DataGasPrice)
}

Check warning on line 1172 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1170-L1172

Added lines #L1170 - L1172 were not covered by tests
if !shadowHeader.L1DataGasPrice.PriceInWei.Equal(sequenceHeader.L1DataGasPrice.PriceInWei) {
return fmt.Errorf("L1 data gas PriceInFri mismatch: shadowHeader L1DataGasPrice %v, sequenceHeader L1DataGasPrice %v",
shadowHeader.L1DataGasPrice, sequenceHeader.L1DataGasPrice)
if !refHeader.L1DataGasPrice.PriceInWei.Equal(sequenceHeader.L1DataGasPrice.PriceInWei) {
return fmt.Errorf("L1 data gas PriceInFri mismatch: reference header L1DataGasPrice %v, sequenced header L1DataGasPrice %v",
refHeader.L1DataGasPrice, sequenceHeader.L1DataGasPrice)
}

Check warning on line 1176 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1174-L1176

Added lines #L1174 - L1176 were not covered by tests
if !shadowHeader.GlobalStateRoot.Equal(sequenceHeader.GlobalStateRoot) {
return fmt.Errorf("global state root mismatch: shadowHeader global state root %v, sequenceHeader global state root %v",
shadowHeader.GlobalStateRoot, sequenceHeader.GlobalStateRoot)
if !refHeader.GlobalStateRoot.Equal(sequenceHeader.GlobalStateRoot) {
return fmt.Errorf("global state root mismatch: reference header global state root %v, sequenced header global state root %v",
refHeader.GlobalStateRoot, sequenceHeader.GlobalStateRoot)
}

Check warning on line 1180 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1178-L1180

Added lines #L1178 - L1180 were not covered by tests
if !shadowHeader.Hash.Equal(sequenceHeader.Hash) {
return fmt.Errorf("hash mismatch: shadowHeader hash %v, sequenceHeader hash %v", shadowHeader.Hash, sequenceHeader.Hash)
if !refHeader.Hash.Equal(sequenceHeader.Hash) {
return fmt.Errorf("hash mismatch: reference header hash %v, sequenced header hash %v", refHeader.Hash, sequenceHeader.Hash)
}

Check warning on line 1183 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1182-L1183

Added lines #L1182 - L1183 were not covered by tests
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (b *Builder) runShadowMode(ctx context.Context) error {

go func() {
if pErr := b.shadowTxns(ctx); pErr != nil {
b.log.Errorw("shadowTxns", "err", pErr)
b.log.Errorw("shadowing transactions", "err", pErr)
}

Check warning on line 253 in builder/builder.go

View check run for this annotation

Codecov / codecov/patch

builder/builder.go#L252-L253

Added lines #L252 - L253 were not covered by tests
}()

Expand Down

0 comments on commit 142ba87

Please sign in to comment.