Skip to content

Commit

Permalink
CLN: Use setter for last cross chain data
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusmihaic committed Dec 18, 2024
1 parent c7bb2e4 commit 3fa601c
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 47 deletions.
2 changes: 1 addition & 1 deletion cmd/node/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@
[EpochStartConfig]
GenesisEpoch = 0
MinRoundsBetweenEpochs = 20
RoundsPerEpoch = 200
RoundsPerEpoch = 30
# Min and Max ShuffledOutRestartThreshold represents the minimum and maximum duration of an epoch (in percentage) after a node which
# has been shuffled out has to restart its process in order to start in a new shard
MinShuffledOutRestartThreshold = 0.05
Expand Down
2 changes: 1 addition & 1 deletion cmd/sovereignnode/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ go 1.20

require (
github.com/google/gops v0.3.18
github.com/multiversx/mx-chain-core-go v1.2.24-0.20241209142414-762196f8dd06
github.com/multiversx/mx-chain-core-go v1.2.24-0.20241218131403-473853d0b54a
github.com/multiversx/mx-chain-go v1.8.4
github.com/multiversx/mx-chain-logger-go v1.0.15
github.com/multiversx/mx-chain-sovereign-bridge-go v0.0.0-20240116102202-4cf6fbbd95a3
Expand Down
4 changes: 2 additions & 2 deletions cmd/sovereignnode/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY
github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o=
github.com/multiversx/mx-chain-communication-go v1.1.1 h1:y4DoQeQOJTaSUsRzczQFazf8JYQmInddypApqA3AkwM=
github.com/multiversx/mx-chain-communication-go v1.1.1/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM=
github.com/multiversx/mx-chain-core-go v1.2.24-0.20241209142414-762196f8dd06 h1:3Sog/pzWhtQ7UKHTaJhK50EjSqlkxTOD4JKWmJZzr50=
github.com/multiversx/mx-chain-core-go v1.2.24-0.20241209142414-762196f8dd06/go.mod h1:P/YBoFnt25XUaCQ7Q/SD15vhnc9yV5JDhHxyFO9P8Z0=
github.com/multiversx/mx-chain-core-go v1.2.24-0.20241218131403-473853d0b54a h1:0w+YAzjGWLV+U3ERmu1TnUUgwjj+3kAbTL4S+vCUa2M=
github.com/multiversx/mx-chain-core-go v1.2.24-0.20241218131403-473853d0b54a/go.mod h1:P/YBoFnt25XUaCQ7Q/SD15vhnc9yV5JDhHxyFO9P8Z0=
github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk=
github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4=
github.com/multiversx/mx-chain-es-indexer-go v1.7.11-0.20241211094055-23de51462ca4 h1:IfjK6IQy65eMWr/FEv3CMUz13ZqH9sWLnKv85/AoayM=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/klauspost/cpuid/v2 v2.2.5
github.com/mitchellh/mapstructure v1.5.0
github.com/multiversx/mx-chain-communication-go v1.1.1
github.com/multiversx/mx-chain-core-go v1.2.24-0.20241209142414-762196f8dd06
github.com/multiversx/mx-chain-core-go v1.2.24-0.20241218131403-473853d0b54a
github.com/multiversx/mx-chain-crypto-go v1.2.12
github.com/multiversx/mx-chain-es-indexer-go v1.7.11-0.20241211094055-23de51462ca4
github.com/multiversx/mx-chain-logger-go v1.0.15
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY
github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o=
github.com/multiversx/mx-chain-communication-go v1.1.1 h1:y4DoQeQOJTaSUsRzczQFazf8JYQmInddypApqA3AkwM=
github.com/multiversx/mx-chain-communication-go v1.1.1/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM=
github.com/multiversx/mx-chain-core-go v1.2.24-0.20241209142414-762196f8dd06 h1:3Sog/pzWhtQ7UKHTaJhK50EjSqlkxTOD4JKWmJZzr50=
github.com/multiversx/mx-chain-core-go v1.2.24-0.20241209142414-762196f8dd06/go.mod h1:P/YBoFnt25XUaCQ7Q/SD15vhnc9yV5JDhHxyFO9P8Z0=
github.com/multiversx/mx-chain-core-go v1.2.24-0.20241218131403-473853d0b54a h1:0w+YAzjGWLV+U3ERmu1TnUUgwjj+3kAbTL4S+vCUa2M=
github.com/multiversx/mx-chain-core-go v1.2.24-0.20241218131403-473853d0b54a/go.mod h1:P/YBoFnt25XUaCQ7Q/SD15vhnc9yV5JDhHxyFO9P8Z0=
github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk=
github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4=
github.com/multiversx/mx-chain-es-indexer-go v1.7.11-0.20241211094055-23de51462ca4 h1:IfjK6IQy65eMWr/FEv3CMUz13ZqH9sWLnKv85/AoayM=
Expand Down
73 changes: 33 additions & 40 deletions process/block/sovereignChainBlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"math/big"
"math/rand"
"sort"
"time"

Expand Down Expand Up @@ -684,13 +683,13 @@ func (scbp *sovereignChainBlockProcessor) requestExtendedShardHeaders(sovereignC

// todo: extra validity check: that there are no extended shard headers added to the epoch start block, only GetLastFinalizedCrossChainHeaderHandler
if len(sovereignChainHeader.GetExtendedShardHeaderHashes()) == 0 {
return scbp.checkAndRequestIfMissingEpochStartExtendedHeader(sovereignChainHeader)
return scbp.computeAndRequestEpochStartExtendedHeaderIfMissing(sovereignChainHeader)
}

return scbp.computeExistingAndRequestMissingExtendedShardHeaders(sovereignChainHeader.GetExtendedShardHeaderHashes())
return scbp.computeExistingAndRequestMissingExtendedShardHeaders(sovereignChainHeader)
}

func (scbp *sovereignChainBlockProcessor) checkAndRequestIfMissingEpochStartExtendedHeader(sovereignChainHeader data.SovereignChainHeaderHandler) uint32 {
func (scbp *sovereignChainBlockProcessor) computeAndRequestEpochStartExtendedHeaderIfMissing(sovereignChainHeader data.SovereignChainHeaderHandler) uint32 {
if !sovereignChainHeader.IsStartOfEpochBlock() {
return 0
}
Expand All @@ -701,48 +700,45 @@ func (scbp *sovereignChainBlockProcessor) checkAndRequestIfMissingEpochStartExte
return 0
}

log.Error("checkAndRequestIfMissingEpochStartExtendedHeader started")

if rand.Int31n(10) > 5 {
log.Error("ADDING CODE TO DELETE HDR")
scbp.dataPool.Headers().RemoveHeaderByHash(lastCrossChainData.GetHeaderHash())
scbp.extendedShardHeaderTracker.DeleteMainChainHeader(lastCrossChainData.GetNonce())
}

scbp.hdrsForCurrBlock.mutHdrsForBlock.Lock()
defer scbp.hdrsForCurrBlock.mutHdrsForBlock.Unlock()
lastCrossChainHash := lastCrossChainData.GetHeaderHash()

_, errMissingHdrPool := process.GetExtendedShardHeaderFromPool(
lastCrossChainData.GetHeaderHash(),
lastCrossChainHash,
scbp.dataPool.Headers())
_, lastNotarizedHdrHash, _ := scbp.blockTracker.GetLastCrossNotarizedHeader(core.MainChainShardId)

_, lastNotarziedHdrHash, errTracker := scbp.blockTracker.GetLastCrossNotarizedHeader(core.MainChainShardId)

missingHeaderInTracker := errTracker != nil && !bytes.Equal(lastNotarziedHdrHash, lastCrossChainData.GetHeaderHash())
missingHeaderInTracker := !bytes.Equal(lastNotarizedHdrHash, lastCrossChainHash)
missingHeaderInPool := errMissingHdrPool != nil
shouldRequestLastCrossChainHeader := missingHeaderInTracker || missingHeaderInPool

log.Error("CHECKING EXTRA VALUES", "errTracker", errTracker, "lastNotarziedHdrHash", lastNotarziedHdrHash, "lastCrossChainData.GetHeaderHash()", lastCrossChainData.GetHeaderHash())

log.Error("CHECKING BOOL VALUES", "missingHeaderInTracker", missingHeaderInTracker, "missingHeaderInPool", missingHeaderInPool)
log.Debug("sovereignChainBlockProcessor.checkAndRequestIfMissingEpochStartExtendedHeader",
"missingHeaderInTracker", missingHeaderInTracker,
"missingHeaderInPool", missingHeaderInPool,
"shouldRequestLastCrossChainHeader", shouldRequestLastCrossChainHeader,
)

if missingHeaderInTracker || missingHeaderInPool {
scbp.hdrsForCurrBlock.missingHdrs++
scbp.hdrsForCurrBlock.hdrHashAndInfo[string(lastCrossChainData.GetHeaderHash())] = &hdrInfo{
hdr: nil,
usedInBlock: false,
}
go scbp.extendedShardHeaderRequester.RequestExtendedShardHeader(lastCrossChainData.GetHeaderHash())
if !shouldRequestLastCrossChainHeader {
return 0
}

return 1
scbp.hdrsForCurrBlock.mutHdrsForBlock.Lock()
scbp.hdrsForCurrBlock.missingHdrs++
scbp.hdrsForCurrBlock.hdrHashAndInfo[string(lastCrossChainHash)] = &hdrInfo{
hdr: nil,
usedInBlock: false,
}
scbp.hdrsForCurrBlock.mutHdrsForBlock.Unlock()

go scbp.extendedShardHeaderRequester.RequestExtendedShardHeader(lastCrossChainHash)

return 0
return 1
}

func (scbp *sovereignChainBlockProcessor) computeExistingAndRequestMissingExtendedShardHeaders(extendedShardHeaderHashes [][]byte) uint32 {
func (scbp *sovereignChainBlockProcessor) computeExistingAndRequestMissingExtendedShardHeaders(sovereignChainHeader data.SovereignChainHeaderHandler) uint32 {
scbp.hdrsForCurrBlock.mutHdrsForBlock.Lock()
defer scbp.hdrsForCurrBlock.mutHdrsForBlock.Unlock()

extendedShardHeaderHashes := sovereignChainHeader.GetExtendedShardHeaderHashes()
for i := 0; i < len(extendedShardHeaderHashes); i++ {
hdr, err := process.GetExtendedShardHeaderFromPool(
extendedShardHeaderHashes[i],
Expand Down Expand Up @@ -1065,15 +1061,12 @@ func (scbp *sovereignChainBlockProcessor) createEpochStartDataCrossChain(sovHdr
"lastCrossNotarizedHeaderNonce", lastCrossNotarizedHeader.GetNonce(),
)

// TODO: Make setter directly here in core
return sovHdr.GetEpochStartHandler().SetLastFinalizedHeaders([]data.EpochStartShardDataHandler{
&block.EpochStartCrossChainData{
ShardID: core.MainChainShardId,
Epoch: lastCrossNotarizedHeader.GetEpoch(),
Round: lastCrossNotarizedHeader.GetRound(),
Nonce: lastCrossNotarizedHeader.GetNonce(),
HeaderHash: lastCrossNotarizedHeaderHash,
},
return sovHdr.SetLastFinalizedCrossChainHeaderHandler(&block.EpochStartCrossChainData{
ShardID: core.MainChainShardId,
Epoch: lastCrossNotarizedHeader.GetEpoch(),
Round: lastCrossNotarizedHeader.GetRound(),
Nonce: lastCrossNotarizedHeader.GetNonce(),
HeaderHash: lastCrossNotarizedHeaderHash,
})
}

Expand Down
1 change: 1 addition & 0 deletions process/track/blockNotarizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/hashing"
"github.com/multiversx/mx-chain-core-go/marshal"

"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/sharding"
)
Expand Down

0 comments on commit 3fa601c

Please sign in to comment.