Skip to content

Commit

Permalink
Fix rebase conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkushinDaniil committed Nov 7, 2024
1 parent da2ead3 commit 184cd8d
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 64 deletions.
4 changes: 2 additions & 2 deletions adapters/core2p2p/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func AdaptBlockID(header *core.Header) *spec.BlockID {
}
}

func AdaptSignature(sig []*felt.Felt) *spec.ConsensusSignature {
func adaptSignature(sig []*felt.Felt) *spec.ConsensusSignature {
return &spec.ConsensusSignature{
R: AdaptFelt(sig[0]),
S: AdaptFelt(sig[1]),
Expand Down Expand Up @@ -48,7 +48,7 @@ func AdaptHeader(header *core.Header, commitments *core.BlockCommitments,
Receipts: AdaptHash(commitments.ReceiptCommitment),
ProtocolVersion: header.ProtocolVersion,
GasPriceFri: AdaptUint128(header.GasPriceSTRK),
Signatures: utils.Map(header.Signatures, AdaptSignature),
Signatures: utils.Map(header.Signatures, adaptSignature),
StateDiffCommitment: &spec.StateDiffCommitment{
StateDiffLength: stateDiffLength,
Root: AdaptHash(stateDiffCommitment),
Expand Down
1 change: 0 additions & 1 deletion adapters/core2p2p/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ func AdaptExecutionResources(er *core.ExecutionResources) *spec.Receipt_Executio
if da := er.DataAvailability; da != nil { // todo(kirill) check that it might be null
l1Gas = new(felt.Felt).SetUint64(da.L1Gas)
l1DataGas = new(felt.Felt).SetUint64(da.L1DataGas)

}
if tgs := er.TotalGasConsumed; tgs != nil {
totalL1Gas = new(felt.Felt).SetUint64(tgs.L1Gas)
Expand Down
4 changes: 2 additions & 2 deletions adapters/p2p2core/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func AdaptBlockHeader(h *spec.SignedBlockHeader, eventsBloom *bloom.BloomFilter)
PriceInWei: AdaptUint128(h.DataGasPriceWei),
PriceInFri: AdaptUint128(h.DataGasPriceFri),
},
GasPrice: AdaptUint128(h.GasPriceWei),
GasPriceSTRK: AdaptUint128(h.GasPriceFri),
GasPrice: AdaptUint128(h.GasPriceFri),
GasPriceSTRK: AdaptUint128(h.GasPriceWei),
}
}

Expand Down
12 changes: 11 additions & 1 deletion blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type Reader interface {
BlockByNumber(number uint64) (block *core.Block, err error)
BlockByHash(hash *felt.Felt) (block *core.Block, err error)

BlockP2PHashByNumber(number uint64) (hash *felt.Felt, err error)

HeadsHeader() (header *core.Header, err error)
BlockHeaderByNumber(number uint64) (header *core.Header, err error)
BlockHeaderByHash(hash *felt.Felt) (header *core.Header, err error)
Expand Down Expand Up @@ -369,21 +371,29 @@ func (b *Blockchain) Store(block *core.Block, blockCommitments *core.BlockCommit
return err
}

fmt.Println("block.ProtocolVersion", block.ProtocolVersion)

blockVer, err := core.ParseBlockVersion(block.ProtocolVersion)
if err != nil {
return err
}

fmt.Println("blockVer", blockVer)

if blockVer.LessThan(core.Ver0_13_2) {
// temporary hack
fmt.Println("block.SequencerAddress", block.SequencerAddress)
if block.SequencerAddress == nil {
block.SequencerAddress = &felt.Zero
}
fmt.Println("ComputeAndStoreP2PHash")
if err := ComputeAndStoreP2PHash(txn, block, stateUpdate.StateDiff); err != nil {
return err
}
}

fmt.Println("blockCommitments", blockCommitments)

if err := StoreBlockCommitments(txn, block.Number, blockCommitments); err != nil {
return err
}
Expand Down Expand Up @@ -884,7 +894,7 @@ func (b *Blockchain) GetReverseStateDiff() (*core.StateDiff, error) {
if err != nil {
return err
}
stateUpdate, err := stateUpdateByNumber(txn, blockNumber)
stateUpdate, err := StateUpdateByNumber(txn, blockNumber)
if err != nil {
return err
}
Expand Down
15 changes: 13 additions & 2 deletions core/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"slices"

"github.com/Masterminds/semver/v3"
"github.com/NethermindEth/juno/core/crypto"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/utils"
Expand Down Expand Up @@ -127,6 +126,19 @@ func VerifyBlockHash(b *Block, network *utils.Network, stateDiff *StateDiff) (*B
return nil, errors.New("can not verify hash in block header")
}

// BlockHash assumes block.SequencerAddress is not nil as this is called with post v0.12.0
// and by then issues with unverifiable block hash were resolved.
// In future, this may no longer be required.
// Todo: Pass stateDiff so that p2p layer can calculate post 0.13.2 Block Hash
func BlockHash(b *Block) (*felt.Felt, error) {
if b.SequencerAddress == nil {
return nil, errors.New("block.SequencerAddress is nil")
}

h, _, err := post07Hash(b, nil)
return h, err
}

// blockHash computes the block hash, with option to override sequence address
func blockHash(b *Block, stateDiff *StateDiff, network *utils.Network, overrideSeqAddr *felt.Felt) (*felt.Felt,
*BlockCommitments, error,
Expand All @@ -137,7 +149,6 @@ func blockHash(b *Block, stateDiff *StateDiff, network *utils.Network, overrideS
if err != nil {
return nil, nil, err
}
v0_13_2 := semver.MustParse("0.13.2")

if blockVer.LessThan(Ver0_13_2) {
if b.Number < metaInfo.First07Block {
Expand Down
1 change: 1 addition & 0 deletions db/buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
BlockCommitments
Temporary // used temporarily for migrations
SchemaIntermediateState
P2PHash
)

// Key flattens a prefix and series of byte arrays into a single []byte.
Expand Down
56 changes: 0 additions & 56 deletions p2p/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,62 +76,6 @@ func (s *syncService) start(ctx context.Context) {
continue
}

txsCh, err := s.genTransactions(iterCtx, blockNumber)
if err != nil {
s.logError("Failed to get transactions", err)
cancelIteration()
continue
}

eventsCh, err := s.genEvents(iterCtx, blockNumber)
if err != nil {
s.logError("Failed to get classes", err)
cancelIteration()
continue
}

classesCh, err := s.genClasses(iterCtx, blockNumber)
if err != nil {
s.logError("Failed to get classes", err)
cancelIteration()
continue
}

stateDiffsCh, err := s.genStateDiffs(iterCtx, blockNumber)
if err != nil {
s.logError("Failed to get state diffs", err)
cancelIteration()
continue
}

blocksCh := pipeline.Bridge(iterCtx, s.processSpecBlockParts(iterCtx, uint64(nextHeight), pipeline.FanIn(iterCtx,
pipeline.Stage(iterCtx, headersAndSigsCh, specBlockPartsFunc[specBlockHeaderAndSigs]),
pipeline.Stage(iterCtx, classesCh, specBlockPartsFunc[specClasses]),
pipeline.Stage(iterCtx, stateDiffsCh, specBlockPartsFunc[specContractDiffs]),
pipeline.Stage(iterCtx, txsCh, specBlockPartsFunc[specTxWithReceipts]),
pipeline.Stage(iterCtx, eventsCh, specBlockPartsFunc[specEvents]),
)))

for b := range blocksCh {
if b.err != nil {
// cannot process any more blocks
s.log.Errorw("Failed to process block", "err", b.err)
cancelIteration()
break
}

storeTimer := time.Now()
err = s.blockchain.Store(b.block, b.commitments, b.stateUpdate, b.newClasses)
if err != nil {
s.log.Errorw("Failed to Store Block", "number", b.block.Number, "err", err)
cancelIteration()
break
}

s.log.Infow("Stored Block", "number", b.block.Number, "hash", b.block.Hash.ShortString(),
"root", b.block.GlobalStateRoot.ShortString())
s.listener.OnSyncStepDone(junoSync.OpStore, b.block.Number, time.Since(storeTimer))
}
cancelIteration()
}
}
Expand Down

0 comments on commit 184cd8d

Please sign in to comment.