Skip to content

Commit

Permalink
Fix tests failed due to nil values
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkushinDaniil committed Nov 8, 2024
1 parent a73ede5 commit b614a35
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
8 changes: 2 additions & 6 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,7 @@ func (b *Blockchain) Store(block *core.Block, blockCommitments *core.BlockCommit
}

if blockVer.LessThan(core.Ver0_13_2) {
// temporary hack
if block.SequencerAddress == nil {
block.SequencerAddress = &felt.Zero
}
if err := ComputeAndStoreP2PHash(txn, block, stateUpdate.StateDiff); err != nil {
if err := computeAndStoreP2PHash(txn, block, stateUpdate.StateDiff); err != nil {
return err
}
}
Expand All @@ -408,7 +404,7 @@ func (b *Blockchain) VerifyBlock(block *core.Block) error {
})
}

func ComputeAndStoreP2PHash(txn db.Transaction, block *core.Block, stateDiff *core.StateDiff) error {
func computeAndStoreP2PHash(txn db.Transaction, block *core.Block, stateDiff *core.StateDiff) error {
hash, _, err := core.Post0132Hash(block, stateDiff)
if err != nil {
return err
Expand Down
37 changes: 29 additions & 8 deletions core/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,21 +216,42 @@ func Post0132Hash(b *Block, stateDiff *StateDiff) (*felt.Felt, *BlockCommitments

concatCounts := concatCounts(b.TransactionCount, b.EventCount, sdLength, b.L1DAMode)

// temporary hack
seqAddr := &felt.Zero
gasPriceStrk := &felt.Zero
l1DataGasPricrInWei := &felt.Zero
l1DataGasPriceInFri := &felt.Zero

if b.SequencerAddress != nil {
seqAddr = b.SequencerAddress
}
if b.GasPriceSTRK != nil {
gasPriceStrk = b.GasPriceSTRK
}
if b.L1DataGasPrice != nil {
if b.L1DataGasPrice.PriceInWei != nil {
l1DataGasPricrInWei = b.L1DataGasPrice.PriceInWei
}
if b.L1DataGasPrice.PriceInFri != nil {
l1DataGasPriceInFri = b.L1DataGasPrice.PriceInFri
}
}

return crypto.PoseidonArray(
new(felt.Felt).SetBytes([]byte("STARKNET_BLOCK_HASH0")),
new(felt.Felt).SetUint64(b.Number), // block number
b.GlobalStateRoot, // global state root
b.SequencerAddress, // sequencer address
seqAddr, // sequencer address
new(felt.Felt).SetUint64(b.Timestamp), // block timestamp
concatCounts,
sdCommitment,
txCommitment, // transaction commitment
eCommitment, // event commitment
rCommitment, // receipt commitment
b.GasPrice, // gas price in wei
b.GasPriceSTRK, // gas price in fri
b.L1DataGasPrice.PriceInWei,
b.L1DataGasPrice.PriceInFri,
txCommitment, // transaction commitment
eCommitment, // event commitment
rCommitment, // receipt commitment
b.GasPrice, // gas price in wei
gasPriceStrk, // gas price in fri
l1DataGasPricrInWei,
l1DataGasPriceInFri,
new(felt.Felt).SetBytes([]byte(b.ProtocolVersion)),
&felt.Zero, // reserved: extra data
b.ParentHash, // parent block hash
Expand Down

0 comments on commit b614a35

Please sign in to comment.