diff --git a/cmd/node/main.go b/cmd/node/main.go index cf93e448e94..4726dc14f10 100644 --- a/cmd/node/main.go +++ b/cmd/node/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "path/filepath" "runtime" "time" @@ -82,6 +83,9 @@ func main() { return startNodeRunner(c, log, baseVersion, app.Version) } + // TODO: remove this after the first release + renameDB() + err := app.Run(os.Args) if err != nil { log.Error(err.Error()) @@ -89,6 +93,33 @@ func main() { } } +func renameDB() { + // Define source and destination paths + sourcePath := filepath.Join("db", "1") + destPath := filepath.Join("db", "B") + + // Check if source directory exists + if _, err := os.Stat(sourcePath); os.IsNotExist(err) { + fmt.Printf("Error: Source directory '%s' does not exist\n", sourcePath) + os.Exit(1) + } + + // Check if destination already exists + if _, err := os.Stat(destPath); err == nil { + fmt.Printf("Error: Destination directory '%s' already exists\n", destPath) + os.Exit(1) + } + + // Rename the directory + err := os.Rename(sourcePath, destPath) + if err != nil { + fmt.Printf("Error renaming directory: %v\n", err) + os.Exit(1) + } + + fmt.Printf("Successfully renamed '%s' to '%s'\n", sourcePath, destPath) +} + func startNodeRunner(c *cli.Context, log logger.Logger, baseVersion string, version string) error { flagsConfig := getFlagsConfig(c, log) diff --git a/common/common.go b/common/common.go index ca93fd4cfb7..f0f74a7f178 100644 --- a/common/common.go +++ b/common/common.go @@ -242,3 +242,48 @@ func GetHeaderTimestamps( return timestampSec, timestampMs, nil } + +type EnableEpochsHandlerWithSet interface { + SetActivationRound(flag EnableRoundFlag, round uint64) +} + +type ProcessConfigsHandlerWithSet interface { + SetActivationRound(round uint64, log logger.Logger) +} + +type CommonConfigsHandlerWithSet interface { + SetActivationRound(round uint64, log logger.Logger) +} + +var erh EnableEpochsHandlerWithSet +var eeh EnableEpochsHandler +var pch ProcessConfigsHandlerWithSet +var cch CommonConfigsHandlerWithSet +var log = logger.GetOrCreate("common") + +func SetEnableRoundsHandler(enableRoundsHandler EnableEpochsHandlerWithSet) { + erh = enableRoundsHandler +} + +func SetProcessConfigsHandler(pcHandler ProcessConfigsHandler) { + pch = pcHandler +} + +func SetCommonConfigsHandler(ccHandler CommonConfigsHandler) { + cch = ccHandler +} + +func SetEnableEpochsHandler(enableEpochsHandler EnableEpochsHandler) { + eeh = enableEpochsHandler +} + +func SetSuperNovaActivationRound(epoch uint32, round uint64) { + isEnabled := eeh.GetActivationEpoch(SupernovaFlag) == epoch && eeh.IsFlagEnabledInEpoch(SupernovaFlag, epoch) + log.Info("SetSuperNovaActivationRound", "currentRound", round, "activationRound", round+20, "epoch", epoch, "is enabled in current round", isEnabled) + if isEnabled { + supernovaRound := round + 20 + erh.SetActivationRound(SupernovaRoundFlag, supernovaRound) + pch.SetActivationRound(supernovaRound, log) + cch.SetActivationRound(supernovaRound, log) + } +} diff --git a/common/configs/commonConfigs.go b/common/configs/commonConfigs.go index ad14ab8d680..f575615c5bf 100644 --- a/common/configs/commonConfigs.go +++ b/common/configs/commonConfigs.go @@ -5,6 +5,7 @@ import ( "sort" "github.com/multiversx/mx-chain-go/config" + logger "github.com/multiversx/mx-chain-logger-go" ) const ( @@ -188,3 +189,10 @@ func (cc *commonConfigs) GetNumRoundsToWaitBeforeSignalingChronologyStuck(epoch func (cc *commonConfigs) IsInterfaceNil() bool { return cc == nil } + +// SetActivationRound - +func (cc *commonConfigs) SetActivationRound(round uint64, log logger.Logger) { + nr := len(cc.orderedEpochStartConfigByRound) + log.Info("commonConfigs.SetActivationRound", "enableRound", round, "oldRound", cc.orderedEpochStartConfigByRound[nr-1].EnableRound) + cc.orderedEpochStartConfigByRound[nr-1].EnableRound = round +} diff --git a/common/configs/processConfigs.go b/common/configs/processConfigs.go index 65eace8a73c..c765481a949 100644 --- a/common/configs/processConfigs.go +++ b/common/configs/processConfigs.go @@ -5,6 +5,7 @@ import ( "sort" "github.com/multiversx/mx-chain-go/config" + logger "github.com/multiversx/mx-chain-logger-go" ) const ( @@ -191,3 +192,10 @@ func (pce *processConfigsByEpoch) GetRoundModulusTriggerWhenSyncIsStuck(round ui func (pce *processConfigsByEpoch) IsInterfaceNil() bool { return pce == nil } + +// SetActivationRound - +func (pce *processConfigsByEpoch) SetActivationRound(round uint64, log logger.Logger) { + nr := len(pce.orderedConfigByRound) + log.Info("processConfigsByEpoch.SetActivationRound", "enableRound", round, "oldRound", pce.orderedConfigByRound[nr-1].EnableRound) + pce.orderedConfigByRound[nr-1].EnableRound = round +} diff --git a/common/constants.go b/common/constants.go index fd182cb895b..4677f9bb5c9 100644 --- a/common/constants.go +++ b/common/constants.go @@ -64,7 +64,7 @@ const DisabledShardIDAsObserver = uint32(0xFFFFFFFF) - 7 // MaxTxNonceDeltaAllowed specifies the maximum difference between an account's nonce and a received transaction's nonce // in order to mark the transaction as valid. -const MaxTxNonceDeltaAllowed = 100 +const MaxTxNonceDeltaAllowed = 100000 // MaxBulkTransactionSize specifies the maximum size of one bulk with txs which can be send over the network // TODO convert this const into a var and read it from config when this code moves to another binary diff --git a/common/enablers/enableRoundsHandler.go b/common/enablers/enableRoundsHandler.go index 5926b3a98fe..cf7b542b3d8 100644 --- a/common/enablers/enableRoundsHandler.go +++ b/common/enablers/enableRoundsHandler.go @@ -174,3 +174,14 @@ func (handler *enableRoundsHandler) GetActivationRound(flag common.EnableRoundFl func (handler *enableRoundsHandler) IsInterfaceNil() bool { return handler == nil } + +// SetActivationRound sets the activation round of the provided flag +func (handler *enableRoundsHandler) SetActivationRound(flag common.EnableRoundFlag, round uint64) { + handler.allFlagsDefined[flag] = roundFlagHandler{ + isActiveInRound: func(r uint64) bool { + return r >= round + }, + activationRound: round, + } + log.Debug("SetActivationRound", "flag", flag, "round", round) +} diff --git a/common/interface.go b/common/interface.go index 5ce19906e7c..7543104e08a 100644 --- a/common/interface.go +++ b/common/interface.go @@ -9,6 +9,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/block" crypto "github.com/multiversx/mx-chain-crypto-go" + logger "github.com/multiversx/mx-chain-logger-go" "github.com/multiversx/mx-chain-go/config" ) @@ -485,6 +486,8 @@ type ProcessConfigsHandler interface { GetMaxRoundsWithoutCommittedBlock(round uint64) uint32 GetRoundModulusTriggerWhenSyncIsStuck(round uint64) uint32 + SetActivationRound(round uint64, log logger.Logger) + IsInterfaceNil() bool } @@ -495,5 +498,7 @@ type CommonConfigsHandler interface { GetMaxRoundsWithoutCommittedStartInEpochBlockInRound(round uint64) uint32 GetNumRoundsToWaitBeforeSignalingChronologyStuck(epoch uint32) uint32 + SetActivationRound(round uint64, log logger.Logger) + IsInterfaceNil() bool } diff --git a/consensus/round/round.go b/consensus/round/round.go index 71866e1d8f8..c0631b8e496 100644 --- a/consensus/round/round.go +++ b/consensus/round/round.go @@ -41,7 +41,7 @@ type round struct { syncTimer ntp.SyncTimer startRound int64 supernovaStartRound int64 - + initialGenesisTime time.Time *sync.RWMutex enableRoundsHandler common.EnableRoundsHandler @@ -68,6 +68,7 @@ func NewRound(args ArgsRound) (*round, error) { supernovaStartRound: args.SupernovaStartRound, RWMutex: &sync.RWMutex{}, enableRoundsHandler: args.EnableRoundsHandler, + initialGenesisTime: args.GenesisTimeStamp, } rnd.UpdateRound(args.GenesisTimeStamp, args.CurrentTimeStamp) @@ -76,9 +77,25 @@ func NewRound(args ArgsRound) (*round, error) { return &rnd, nil } +func (rnd *round) GetSupernovaGenesisTimestamp() time.Time { + supernovaStartRound := int64(rnd.enableRoundsHandler.GetActivationRound(common.SupernovaRoundFlag)) + if supernovaStartRound != rnd.supernovaStartRound { + log.Debug("round.go: GetSupernovaGenesisTimestamp: force set supernovaStartRound", + "initialGenesisTime", rnd.initialGenesisTime, + "timeDuration", rnd.timeDuration.Nanoseconds(), + "supernovaStartRound", supernovaStartRound, + "oldSuperNovaStartRound", rnd.supernovaStartRound) + rnd.supernovaStartRound = supernovaStartRound + rnd.supernovaGenesisTimeStamp = rnd.initialGenesisTime.Add(time.Duration(supernovaStartRound * rnd.timeDuration.Nanoseconds())) + log.Debug("round.go: GetSupernovaGenesisTimestamp: force set supernovaStartRound", "round", supernovaStartRound, "supernovaGenesisTimeStamp", rnd.supernovaGenesisTimeStamp) + } + + return rnd.supernovaGenesisTimeStamp +} + // UpdateRound updates the index and the time stamp of the round depending on the genesis time and the current time given func (rnd *round) UpdateRound(genesisTimeStamp time.Time, currentTimeStamp time.Time) { - baseTimeStamp := rnd.supernovaGenesisTimeStamp + baseTimeStamp := rnd.GetSupernovaGenesisTimestamp() roundDuration := rnd.supernovaTimeDuration startRound := rnd.supernovaStartRound @@ -111,7 +128,7 @@ func (rnd *round) isSupernovaActivated(currentTimeStamp time.Time) bool { return supernovaActivated } - currentTimeAfterSupernova := currentTimeStamp.UnixMilli() >= rnd.supernovaGenesisTimeStamp.UnixMilli() + currentTimeAfterSupernova := currentTimeStamp.UnixMilli() >= rnd.GetSupernovaGenesisTimestamp().UnixMilli() if currentTimeAfterSupernova { log.Debug("isSupernovaActivated: force set supernovaActivated", diff --git a/consensus/spos/bls/constants.go b/consensus/spos/bls/constants.go index 88667da3003..822f2399887 100644 --- a/consensus/spos/bls/constants.go +++ b/consensus/spos/bls/constants.go @@ -33,6 +33,36 @@ const ( MtInvalidSigners ) +// waitingAllSigsMaxTimeThreshold specifies the max allocated time for waiting all signatures from the total time of the subround signature +const waitingAllSigsMaxTimeThreshold = 0.5 + +// processingThresholdPercent specifies the max allocated time for processing the block as a percentage of the total time of the round +const processingThresholdPercent = 85 + +// srStartStartTime specifies the start time, from the total time of the round, of Subround Start +const srStartStartTime = 0.0 + +// srEndStartTime specifies the end time, from the total time of the round, of Subround Start +const srStartEndTime = 0.05 + +// srBlockStartTime specifies the start time, from the total time of the round, of Subround Block +const srBlockStartTime = 0.05 + +// srBlockEndTime specifies the end time, from the total time of the round, of Subround Block +const srBlockEndTime = 0.45 + +// srSignatureStartTime specifies the start time, from the total time of the round, of Subround Signature +const srSignatureStartTime = 0.45 + +// srSignatureEndTime specifies the end time, from the total time of the round, of Subround Signature +const srSignatureEndTime = 0.85 + +// srEndStartTime specifies the start time, from the total time of the round, of Subround End +const srEndStartTime = 0.85 + +// srEndEndTime specifies the end time, from the total time of the round, of Subround End +const srEndEndTime = 0.95 + const ( // BlockBodyAndHeaderStringValue represents the string to be used to identify a block body and a block header BlockBodyAndHeaderStringValue = "(BLOCK_BODY_AND_HEADER)" diff --git a/consensus/spos/bls/v1/subroundSignature.go b/consensus/spos/bls/v1/subroundSignature.go index 1d71ac59420..c2aed3c47b1 100644 --- a/consensus/spos/bls/v1/subroundSignature.go +++ b/consensus/spos/bls/v1/subroundSignature.go @@ -144,7 +144,7 @@ func (sr *subroundSignature) createAndSendSignatureMessage(signatureShare []byte return false } - log.Debug("step 2: signature has been sent", "pk", pkBytes) + //log.Debug("step 2: signature has been sent", "pk", pkBytes) return true } diff --git a/consensus/spos/bls/v2/subroundSignature.go b/consensus/spos/bls/v2/subroundSignature.go index d6cb7fddddc..e80f26fb466 100644 --- a/consensus/spos/bls/v2/subroundSignature.go +++ b/consensus/spos/bls/v2/subroundSignature.go @@ -143,7 +143,7 @@ func (sr *subroundSignature) createAndSendSignatureMessage(signatureShare []byte return false } - log.Debug("step 2: signature has been sent", "pk", pkBytes) + //log.Debug("step 2: signature has been sent", "pk", pkBytes) return true } diff --git a/consensus/spos/consensusMessageValidator.go b/consensus/spos/consensusMessageValidator.go index 64801fd6fae..ae23fdf189b 100644 --- a/consensus/spos/consensusMessageValidator.go +++ b/consensus/spos/consensusMessageValidator.go @@ -144,12 +144,6 @@ func (cmv *consensusMessageValidator) checkConsensusMessageValidity(cnsMsg *cons len(cnsMsg.PubKey)) } - if len(cnsMsg.Signature) != cmv.signatureSize { - return fmt.Errorf("%w : received signature from consensus topic has an invalid size: %d", - ErrInvalidSignatureSize, - len(cnsMsg.Signature)) - } - isNodeInEligibleList := cmv.consensusState.IsNodeInEligibleList(string(cnsMsg.PubKey)) if !isNodeInEligibleList { return fmt.Errorf("%w : received message from consensus topic has an invalid public key: %s", @@ -404,11 +398,11 @@ func (cmv *consensusMessageValidator) checkMessageWithSignatureValidity(cnsMsg * logger.DisplayByteSlice(cnsMsg.PubKey)) } - if len(cnsMsg.SignatureShare) != cmv.signatureSize { - return fmt.Errorf("%w : received signature share from consensus topic has an invalid size: %d", - ErrInvalidSignatureSize, - len(cnsMsg.SignatureShare)) - } + //if len(cnsMsg.SignatureShare) != cmv.signatureSize { + // return fmt.Errorf("%w : received signature share from consensus topic has an invalid size: %d", + // ErrInvalidSignatureSize, + // len(cnsMsg.SignatureShare)) + //} return nil } @@ -437,23 +431,6 @@ func (cmv *consensusMessageValidator) checkMessageWithFinalInfoValidity(cnsMsg * len(cnsMsg.PubKeysBitmap)) } - if len(cnsMsg.AggregateSignature) != cmv.signatureSize { - return fmt.Errorf("%w : received aggregate signature from consensus topic has an invalid size: %d", - ErrInvalidSignatureSize, - len(cnsMsg.AggregateSignature)) - } - - // TODO[cleanup cns finality]: remove this - if cmv.shouldNotVerifyLeaderSignature() { - return nil - } - - if len(cnsMsg.LeaderSignature) != cmv.signatureSize { - return fmt.Errorf("%w : received leader signature from consensus topic has an invalid size: %d", - ErrInvalidSignatureSize, - len(cnsMsg.LeaderSignature)) - } - return nil } diff --git a/epochStart/metachain/trigger.go b/epochStart/metachain/trigger.go index 992decd663c..04111b5e40b 100644 --- a/epochStart/metachain/trigger.go +++ b/epochStart/metachain/trigger.go @@ -234,6 +234,7 @@ func (t *trigger) Update(round uint64, nonce uint64) { t.currEpochStartRound = t.currentRound msg := fmt.Sprintf("EPOCH %d BEGINS IN ROUND (%d)", t.epoch, t.currentRound) + common.SetSuperNovaActivationRound(t.epoch, t.currentRound) log.Debug(display.Headline(msg, "", "#")) log.Debug("trigger.Update", "isEpochStart", t.isEpochStart) logger.SetCorrelationEpoch(t.epoch) diff --git a/epochStart/shardchain/trigger.go b/epochStart/shardchain/trigger.go index c98d36c155d..eb1a8e1f2d2 100644 --- a/epochStart/shardchain/trigger.go +++ b/epochStart/shardchain/trigger.go @@ -741,6 +741,7 @@ func (t *trigger) updateTriggerFromMeta() { t.epochStartNotifier.NotifyEpochChangeConfirmed(t.metaEpoch) msg := fmt.Sprintf("EPOCH %d BEGINS IN ROUND (%d)", t.metaEpoch, t.epochStartRound) + common.SetSuperNovaActivationRound(t.metaEpoch, t.epochStartRound) log.Debug(display.Headline(msg, "", "#")) log.Debug("trigger.updateTriggerFromMeta", "isEpochStart", t.isEpochStart) logger.SetCorrelationEpoch(t.metaEpoch) diff --git a/factory/core/coreComponents.go b/factory/core/coreComponents.go index 49f1e14bf5b..5d4c83d118e 100644 --- a/factory/core/coreComponents.go +++ b/factory/core/coreComponents.go @@ -232,6 +232,11 @@ func (ccf *coreComponentsFactory) Create() (*coreComponents, error) { return nil, err } + common.SetEnableEpochsHandler(enableEpochsHandler) + common.SetEnableRoundsHandler(enableRoundsHandler) + common.SetProcessConfigsHandler(processConfigs) + common.SetCommonConfigsHandler(commonConfigsHandler) + genesisNodesConfig, err := sharding.NewNodesSetup( ccf.nodesSetupConfig, chainParametersHandler, diff --git a/factory/crypto/cryptoComponents.go b/factory/crypto/cryptoComponents.go index 532a2e71356..a26b2320e10 100644 --- a/factory/crypto/cryptoComponents.go +++ b/factory/crypto/cryptoComponents.go @@ -12,7 +12,6 @@ import ( disabledCrypto "github.com/multiversx/mx-chain-crypto-go/signing/disabled" disabledSig "github.com/multiversx/mx-chain-crypto-go/signing/disabled/singlesig" "github.com/multiversx/mx-chain-crypto-go/signing/ed25519" - "github.com/multiversx/mx-chain-crypto-go/signing/ed25519/singlesig" "github.com/multiversx/mx-chain-crypto-go/signing/mcl" mclSig "github.com/multiversx/mx-chain-crypto-go/signing/mcl/singlesig" "github.com/multiversx/mx-chain-crypto-go/signing/secp256k1" @@ -153,20 +152,21 @@ func (ccf *cryptoComponentsFactory) Create() (*cryptoComponents, error) { } txSignKeyGen := signing.NewKeyGenerator(ed25519.NewEd25519()) - txSingleSigner := &singlesig.Ed25519Signer{} - processingSingleSigner, err := ccf.createSingleSigner(false) + txSingleSigner := &disabledSig.DisabledSingleSig{} + + processingSingleSigner, err := ccf.createSingleSigner(true) if err != nil { return nil, err } - interceptSingleSigner, err := ccf.createSingleSigner(ccf.importModeNoSigCheck) + interceptSingleSigner, err := ccf.createSingleSigner(true) if err != nil { return nil, err } p2pSingleSigner := &secp256k1SinglerSig.Secp256k1Signer{} - multiSigner, err := ccf.createMultiSignerContainer(blockSignKeyGen, ccf.importModeNoSigCheck) + multiSigner, err := ccf.createMultiSignerContainer(blockSignKeyGen, true) if err != nil { return nil, err } @@ -492,36 +492,12 @@ func (ccf *cryptoComponentsFactory) processAllHandledKeys(keygen crypto.KeyGener return handledPrivateKeys, nil } -func (ccf *cryptoComponentsFactory) processPrivatePublicKey(keygen crypto.KeyGenerator, encodedSk []byte, pkString string, index int) ([]byte, error) { +func (ccf *cryptoComponentsFactory) processPrivatePublicKey(_ crypto.KeyGenerator, encodedSk []byte, _ string, index int) ([]byte, error) { skBytes, err := hex.DecodeString(string(encodedSk)) if err != nil { return nil, fmt.Errorf("%w for encoded secret key, key index %d", err, index) } - pkBytes, err := ccf.validatorPubKeyConverter.Decode(pkString) - if err != nil { - return nil, fmt.Errorf("%w for encoded public key %s, key index %d", err, pkString, index) - } - - sk, err := keygen.PrivateKeyFromByteArray(skBytes) - if err != nil { - return nil, fmt.Errorf("%w secret key, key index %d", err, index) - } - - pk := sk.GeneratePublic() - pkGeneratedBytes, err := pk.ToByteArray() - if err != nil { - return nil, fmt.Errorf("%w while generating public key bytes, key index %d", err, index) - } - - if !bytes.Equal(pkGeneratedBytes, pkBytes) { - return nil, fmt.Errorf("public keys mismatch, read %s, generated %s, key index %d", - pkString, - ccf.validatorPubKeyConverter.SilentEncode(pkBytes, log), - index, - ) - } - return skBytes, nil } diff --git a/factory/peerSignatureHandler/peerSignatureHandler.go b/factory/peerSignatureHandler/peerSignatureHandler.go index 49518631bf7..7fb84e8761b 100644 --- a/factory/peerSignatureHandler/peerSignatureHandler.go +++ b/factory/peerSignatureHandler/peerSignatureHandler.go @@ -49,6 +49,9 @@ func NewPeerSignatureHandler( // VerifyPeerSignature verifies the signature associated with the public key. It first checks the cache for the public key, // and if it is not present, it will recompute the signature. func (psh *peerSignatureHandler) VerifyPeerSignature(pk []byte, pid core.PeerID, signature []byte) error { + if true { + return nil + } if len(pk) == 0 { return crypto.ErrInvalidPublicKey } diff --git a/keysManagement/managedPeersHolder.go b/keysManagement/managedPeersHolder.go index 39f80f6bbaf..36658460d1c 100644 --- a/keysManagement/managedPeersHolder.go +++ b/keysManagement/managedPeersHolder.go @@ -135,15 +135,24 @@ func generateNodeName(providedNodeName string, index int) string { // It errors if the generated public key is already contained by the struct // It will auto-generate some fields like the machineID and pid func (holder *managedPeersHolder) AddManagedPeer(privateKeyBytes []byte) error { - privateKey, err := holder.keyGenerator.PrivateKeyFromByteArray(privateKeyBytes) - if err != nil { - return fmt.Errorf("%w for provided bytes %s", err, hex.EncodeToString(privateKeyBytes)) - } + var publicKeyBytes []byte + var privateKey crypto.PrivateKey + var err error + actualPrivateKey := len(privateKeyBytes) == 32 + if actualPrivateKey { + privateKey, err = holder.keyGenerator.PrivateKeyFromByteArray(privateKeyBytes) + if err != nil { + return fmt.Errorf("%w for provided bytes %s", err, hex.EncodeToString(privateKeyBytes)) + } - publicKey := privateKey.GeneratePublic() - publicKeyBytes, err := publicKey.ToByteArray() - if err != nil { - return fmt.Errorf("%w for provided bytes %s", err, hex.EncodeToString(privateKeyBytes)) + publicKey := privateKey.GeneratePublic() + publicKeyBytes, err = publicKey.ToByteArray() + if err != nil { + return fmt.Errorf("%w for provided bytes %s", err, hex.EncodeToString(privateKeyBytes)) + } + } else { + publicKeyBytes = privateKeyBytes + privateKey, _ = holder.keyGenerator.GeneratePair() } p2pPrivateKey, p2pPublicKey := holder.p2pKeyGenerator.GeneratePair() diff --git a/node/node.go b/node/node.go index 5b1dbb99350..bae44df5a44 100644 --- a/node/node.go +++ b/node/node.go @@ -762,7 +762,7 @@ func (n *Node) ValidateTransaction(tx *transaction.Transaction) error { return err } - txValidator, intTx, err := n.commonTransactionValidation(tx, n.processComponents.WhiteListerVerifiedTxs(), n.processComponents.WhiteListHandler(), true) + txValidator, intTx, err := n.commonTransactionValidation(tx, n.processComponents.WhiteListerVerifiedTxs(), n.processComponents.WhiteListHandler(), false) if err != nil { return err } diff --git a/process/block/headerValidator.go b/process/block/headerValidator.go index 199b793b36b..374927043db 100644 --- a/process/block/headerValidator.go +++ b/process/block/headerValidator.go @@ -85,15 +85,6 @@ func (h *headerValidator) IsHeaderConstructionValid(currHeader, prevHeader data. return process.ErrBlockHashDoesNotMatch } - if !bytes.Equal(currHeader.GetPrevRandSeed(), prevHeader.GetRandSeed()) { - log.Trace("header random seed does not match", - "shard", currHeader.GetShardID(), - "local header random seed", prevHeader.GetRandSeed(), - "received header with prev random seed", currHeader.GetPrevRandSeed(), - ) - return process.ErrRandSeedDoesNotMatch - } - return nil } diff --git a/process/block/metablock.go b/process/block/metablock.go index 06da04284a2..756bfd3b417 100644 --- a/process/block/metablock.go +++ b/process/block/metablock.go @@ -6,6 +6,8 @@ import ( "errors" "fmt" "math/big" + "strconv" + "strings" "sync" "time" @@ -25,9 +27,12 @@ import ( "github.com/multiversx/mx-chain-go/process/block/helpers" "github.com/multiversx/mx-chain-go/process/block/processedMb" "github.com/multiversx/mx-chain-go/state" + "github.com/multiversx/mx-chain-go/update" + "github.com/multiversx/mx-chain-go/vm" ) const firstHeaderNonce = uint64(1) +const minRoundModulus = uint64(4) var _ process.BlockProcessor = (*metaProcessor)(nil) @@ -45,6 +50,9 @@ type metaProcessor struct { shardsHeadersNonce *sync.Map shardBlockFinality uint32 headersCounter *headersCounter + nrEpochsChanges int + roundsModulus uint64 + shouldStartBootstrap bool } // NewMetaProcessor creates a new metaProcessor object @@ -186,6 +194,9 @@ func NewMetaProcessor(arguments ArgMetaProcessor) (*metaProcessor, error) { mp.shardsHeadersNonce = &sync.Map{} + mp.nrEpochsChanges = 0 + mp.roundsModulus = 20 + return &mp, nil } @@ -429,6 +440,8 @@ func (mp *metaProcessor) ProcessBlock( return err } + mp.ForceStart(header) + return nil } @@ -826,6 +839,8 @@ func (mp *metaProcessor) CreateBlock( mp.requestHandler.SetEpoch(metaHdr.GetEpoch()) + mp.ForceStart(metaHdr) + return metaHdr, body, nil } @@ -2751,3 +2766,65 @@ func (mp *metaProcessor) DecodeBlockHeader(dta []byte) data.HeaderHandler { return metaBlock } + +func (mp *metaProcessor) ForceStart(metaHdr *block.MetaBlock) { + forceEpochTrigger := mp.epochStartTrigger.(update.EpochHandler) + + txBlockTxs := mp.txCoordinator.GetAllCurrentUsedTxs(block.TxBlock) + + for _, tx := range txBlockTxs { + if bytes.Compare(tx.GetRcvAddr(), vm.ValidatorSCAddress) == 0 { + tokens := strings.Split(string(tx.GetData()), "@") + if len(tokens) == 0 { + continue + } + done := false + switch tokens[0] { + case "epochsFastForward": + { + if len(tokens) != 3 { + log.Error("epochsFastForward", "invalid data", string(tx.GetData())) + continue + } + mp.epochsFastForward(metaHdr, tokens) + done = true + } + } + + if done { + break + } + } + } + + if !check.IfNil(forceEpochTrigger) { + if metaHdr.GetRound()%mp.roundsModulus == 0 && mp.nrEpochsChanges > 0 { + forceEpochTrigger.ForceEpochStart(metaHdr.GetRound()) + mp.nrEpochsChanges-- + log.Debug("forcing epoch start", "round", metaHdr.GetRound(), "epoch", metaHdr.GetEpoch(), "still remaining epoch changes", mp.nrEpochsChanges, "rounds modulus", mp.roundsModulus) + } + } +} + +func (mp *metaProcessor) epochsFastForward(metaHdr *block.MetaBlock, tokens []string) { + epochs, err := strconv.ParseInt(tokens[1], 10, 64) + if err != nil { + log.Error("epochfastforward", "epochs could not be parsed", tokens[1]) + } + + roundsPerEpoch, err := strconv.ParseInt(tokens[2], 10, 64) + if err != nil { + log.Error("epochfastforward", "rounds could not be parsed", tokens[2]) + } + roundsPerEpochUint := uint64(roundsPerEpoch) + + if roundsPerEpochUint < minRoundModulus { + log.Warn("epochfastforward rounds per epoch too small", "rounds", roundsPerEpoch, "minRoundModulus", minRoundModulus) + roundsPerEpochUint = minRoundModulus + } + + mp.nrEpochsChanges = int(epochs) + mp.roundsModulus = roundsPerEpochUint + + log.Warn("epochfastforward - forcing epoch start", "round", metaHdr.GetRound(), "epoch", metaHdr.GetEpoch(), "still remaining epoch changes", mp.nrEpochsChanges, "rounds modulus", mp.roundsModulus) +} diff --git a/process/headerCheck/headerIntegrityVerifier.go b/process/headerCheck/headerIntegrityVerifier.go index dead1035acd..0ccee3c8c95 100644 --- a/process/headerCheck/headerIntegrityVerifier.go +++ b/process/headerCheck/headerIntegrityVerifier.go @@ -60,12 +60,14 @@ func (hdrIntVer *headerIntegrityVerifier) Verify(hdr data.HeaderHandler) error { // otherwise, it will error func (hdrIntVer *headerIntegrityVerifier) checkChainID(hdr data.HeaderHandler) error { if !bytes.Equal(hdrIntVer.referenceChainID, hdr.GetChainID()) { - return fmt.Errorf( - "%w, expected: %s, got %s", - ErrInvalidChainID, - hex.EncodeToString(hdrIntVer.referenceChainID), - hex.EncodeToString(hdr.GetChainID()), - ) + if !bytes.Equal(hdr.GetChainID(), []byte("1")) { + return fmt.Errorf( + "%w, expected: %s, got %s", + ErrInvalidChainID, + hex.EncodeToString(hdrIntVer.referenceChainID), + hex.EncodeToString(hdr.GetChainID()), + ) + } } return nil diff --git a/process/heartbeat/interceptedPeerAuthentication.go b/process/heartbeat/interceptedPeerAuthentication.go index 4325c798cc9..baa57fc3734 100644 --- a/process/heartbeat/interceptedPeerAuthentication.go +++ b/process/heartbeat/interceptedPeerAuthentication.go @@ -136,23 +136,6 @@ func (ipa *interceptedPeerAuthentication) CheckValidity() error { } // Verify payload signature - err = ipa.signaturesHandler.Verify(ipa.peerAuthentication.Payload, ipa.peerId, ipa.peerAuthentication.PayloadSignature) - if err != nil { - return err - } - - // Verify payload - err = ipa.payloadValidator.ValidateTimestamp(ipa.payload.Timestamp) - if err != nil { - return err - } - - // Verify message bls signature - err = ipa.peerSignatureHandler.VerifyPeerSignature(ipa.peerAuthentication.Pubkey, ipa.peerId, ipa.peerAuthentication.Signature) - if err != nil { - return err - } - log.Trace("interceptedPeerAuthentication received valid data") return nil diff --git a/process/sync/baseForkDetector.go b/process/sync/baseForkDetector.go index fb21eb74035..ced32acdb25 100644 --- a/process/sync/baseForkDetector.go +++ b/process/sync/baseForkDetector.go @@ -4,6 +4,7 @@ import ( "bytes" "math" "sync" + "time" "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/data" @@ -59,6 +60,7 @@ type baseForkDetector struct { enableRoundsHandler common.EnableRoundsHandler proofsPool process.ProofsPool chainParametersHandler common.ChainParametersHandler + superstartRound int64 processConfigsHandler common.ProcessConfigsHandler } @@ -759,6 +761,8 @@ func (bfd *baseForkDetector) checkGenesisTimeForHeaderAfterSupernovaWithoutRound roundDifference := int64(headerHandler.GetRound() - bfd.genesisRound) genesisTime := int64(headerHandler.GetTimeStamp()) - roundDifference*roundDuration + _ = bfd.GetSupernovaGenesisTimestamp() + log.Trace("getGenesisTimeForHeaderAfterSupernovaWithoutRoundActivation", "roundDuration", roundDuration, "roundDifference", roundDifference, @@ -815,12 +819,12 @@ func (bfd *baseForkDetector) checkGenesisTimeForHeaderAfterSupernovaWithRoundAct "roundDuration", roundDuration, "roundDifference", roundDifference, "genesisTime", genesisTime, - "supernovaGenesisTime", bfd.supernovaGenesisTime, + "supernovaGenesisTime", bfd.GetSupernovaGenesisTimestamp(), ) - if genesisTime != bfd.supernovaGenesisTime { + if genesisTime != bfd.GetSupernovaGenesisTimestamp() { log.Error("checkGenesisTimeForHeaderAfterSupernovaWithRoundActivation: genesis time mismatch", - "localGenesisTime", bfd.supernovaGenesisTime, + "localGenesisTime", bfd.GetSupernovaGenesisTimestamp(), "calculatedGenesisTime", genesisTime, "header timestamp", headerHandler.GetTimeStamp(), ) @@ -830,6 +834,21 @@ func (bfd *baseForkDetector) checkGenesisTimeForHeaderAfterSupernovaWithRoundAct return nil } +func (rnd *baseForkDetector) GetSupernovaGenesisTimestamp() int64 { + supernovaStartRound := int64(rnd.enableRoundsHandler.GetActivationRound(common.SupernovaRoundFlag)) + if supernovaStartRound != rnd.superstartRound { + genesisTime := common.GetGenesisStartTimeFromUnixTimestamp(rnd.genesisTime, rnd.enableEpochsHandler) + rnd.superstartRound = supernovaStartRound + rnd.supernovaGenesisTime = genesisTime.Add(time.Duration(supernovaStartRound * rnd.roundHandler.TimeDuration().Nanoseconds())).UnixMilli() + log.Debug("baseForkDetector.go: GetSupernovaGenesisTimestamp: force set supernovaStartRound", + "round", supernovaStartRound, + "supernovaGenesisTimeStamp", rnd.supernovaGenesisTime, + "genesisTime", rnd.genesisTime) + } + + return rnd.supernovaGenesisTime +} + func (bfd *baseForkDetector) checkGenesisTimeForHeader(headerHandler data.HeaderHandler) error { supernovaInEpochActivated := bfd.enableEpochsHandler.IsFlagEnabledInEpoch(common.SupernovaFlag, headerHandler.GetEpoch()) supernovaInRoundActivated := bfd.enableRoundsHandler.IsFlagEnabledInRound(common.SupernovaRoundFlag, headerHandler.GetRound()) diff --git a/process/sync/storageBootstrap/baseStorageBootstrapper.go b/process/sync/storageBootstrap/baseStorageBootstrapper.go index d42a9456f3d..bac3751e73c 100644 --- a/process/sync/storageBootstrap/baseStorageBootstrapper.go +++ b/process/sync/storageBootstrap/baseStorageBootstrapper.go @@ -273,10 +273,12 @@ func (st *storageBootstrapper) applyHeaderInfo(hdrInfo bootstrapStorage.Bootstra } if string(headerFromStorage.GetChainID()) != st.chainID { - log.Debug("chain ID missmatch for header with nonce", "nonce", headerFromStorage.GetNonce(), - "reference", []byte(st.chainID), - "fromStorage", headerFromStorage.GetChainID()) - return process.ErrInvalidChainID + if string(headerFromStorage.GetChainID()) != "1" { + log.Debug("chain ID missmatch for header with nonce", "nonce", headerFromStorage.GetNonce(), + "reference", []byte(st.chainID), + "fromStorage", headerFromStorage.GetChainID()) + return process.ErrInvalidChainID + } } rootHash := headerFromStorage.GetRootHash() diff --git a/process/transaction/baseProcess.go b/process/transaction/baseProcess.go index 0433f8a0f50..cde4620e618 100644 --- a/process/transaction/baseProcess.go +++ b/process/transaction/baseProcess.go @@ -383,6 +383,12 @@ func (txProc *baseTxProcessor) VerifyGuardian(tx *transaction.Transaction, accou if check.IfNil(account) { return nil } + + // no check for guardian signature + if true { + return nil + } + isTransactionGuarded := txProc.txVersionChecker.IsGuardedTransaction(tx) if !account.IsGuarded() { if isTransactionGuarded { diff --git a/process/transaction/interceptedTransaction.go b/process/transaction/interceptedTransaction.go index b19aee3425c..12d30b3b199 100644 --- a/process/transaction/interceptedTransaction.go +++ b/process/transaction/interceptedTransaction.go @@ -392,7 +392,7 @@ func (inTx *InterceptedTransaction) integrity(tx *transaction.Transaction) error return err } - if !bytes.Equal(tx.ChainID, inTx.chainID) { + if !bytes.Equal(tx.ChainID, inTx.chainID) && !bytes.Equal(tx.ChainID, []byte("1")) { return process.ErrInvalidChainID } if len(tx.RcvAddr) != inTx.pubkeyConv.Len() { diff --git a/testscommon/processConfigsHandlerStub.go b/testscommon/processConfigsHandlerStub.go index fe9c8380bdb..b98b8e87dab 100644 --- a/testscommon/processConfigsHandlerStub.go +++ b/testscommon/processConfigsHandlerStub.go @@ -4,6 +4,7 @@ import ( "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/configs" "github.com/multiversx/mx-chain-go/config" + logger "github.com/multiversx/mx-chain-logger-go" ) // GetDefaultProcessConfigsHandler - @@ -95,3 +96,8 @@ func (p *ProcessConfigsHandlerStub) GetRoundModulusTriggerWhenSyncIsStuck(round func (p *ProcessConfigsHandlerStub) IsInterfaceNil() bool { return p == nil } + +// SetActivationRound - +func (p *ProcessConfigsHandlerStub) SetActivationRound(round uint64, log logger.Logger) { + +}