From 3fa601cf6e4566144f23755ee8d8e5db5502672b Mon Sep 17 00:00:00 2001 From: MariusC Date: Wed, 18 Dec 2024 17:28:38 +0200 Subject: [PATCH] CLN: Use setter for last cross chain data --- cmd/node/config/config.toml | 2 +- cmd/sovereignnode/go.mod | 2 +- cmd/sovereignnode/go.sum | 4 +- go.mod | 2 +- go.sum | 4 +- process/block/sovereignChainBlock.go | 73 +++++++++++++--------------- process/track/blockNotarizer.go | 1 + 7 files changed, 41 insertions(+), 47 deletions(-) diff --git a/cmd/node/config/config.toml b/cmd/node/config/config.toml index 6ccb3732763..2aa3c084646 100644 --- a/cmd/node/config/config.toml +++ b/cmd/node/config/config.toml @@ -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 diff --git a/cmd/sovereignnode/go.mod b/cmd/sovereignnode/go.mod index 480286cf9b1..02cd180ccd4 100644 --- a/cmd/sovereignnode/go.mod +++ b/cmd/sovereignnode/go.mod @@ -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 diff --git a/cmd/sovereignnode/go.sum b/cmd/sovereignnode/go.sum index a2be0b00c6a..ee0e9534327 100644 --- a/cmd/sovereignnode/go.sum +++ b/cmd/sovereignnode/go.sum @@ -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= diff --git a/go.mod b/go.mod index d9db1b8c9f3..acfff51064b 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index e52d2230d58..c81bb613277 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/process/block/sovereignChainBlock.go b/process/block/sovereignChainBlock.go index aeae4a2f11c..1b9f7f60a5f 100644 --- a/process/block/sovereignChainBlock.go +++ b/process/block/sovereignChainBlock.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "math/big" - "math/rand" "sort" "time" @@ -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 } @@ -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], @@ -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, }) } diff --git a/process/track/blockNotarizer.go b/process/track/blockNotarizer.go index 0d6b581fd6e..6520d3ff810 100644 --- a/process/track/blockNotarizer.go +++ b/process/track/blockNotarizer.go @@ -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" )