From 8da05ce51b11ca2fef7ee00db8cadf3474c66cc3 Mon Sep 17 00:00:00 2001 From: miiu Date: Thu, 30 Jan 2025 13:43:02 +0200 Subject: [PATCH] sf latest release --- common/constants.go | 2 +- consensus/spos/bls/constants.go | 4 +- consensus/spos/consensusMessageValidator.go | 18 ----- factory/crypto/cryptoComponents.go | 36 ++------- .../peerSignatureHandler.go | 4 + keysManagement/managedPeersHolder.go | 14 +--- node/node.go | 2 +- process/block/headerValidator.go | 9 --- process/block/metablock.go | 77 +++++++++++++++++++ .../interceptedPeerAuthentication.go | 18 ----- process/transaction/baseProcess.go | 5 ++ 11 files changed, 99 insertions(+), 90 deletions(-) diff --git a/common/constants.go b/common/constants.go index e2ed1d80a5a..0c96bf19e55 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/consensus/spos/bls/constants.go b/consensus/spos/bls/constants.go index 166abe70b65..afab1721a2a 100644 --- a/consensus/spos/bls/constants.go +++ b/consensus/spos/bls/constants.go @@ -52,10 +52,10 @@ const srStartEndTime = 0.05 const srBlockStartTime = 0.05 // srBlockEndTime specifies the end time, from the total time of the round, of Subround Block -const srBlockEndTime = 0.25 +const srBlockEndTime = 0.45 // srSignatureStartTime specifies the start time, from the total time of the round, of Subround Signature -const srSignatureStartTime = 0.25 +const srSignatureStartTime = 0.45 // srSignatureEndTime specifies the end time, from the total time of the round, of Subround Signature const srSignatureEndTime = 0.85 diff --git a/consensus/spos/consensusMessageValidator.go b/consensus/spos/consensusMessageValidator.go index 67fa9616e07..2d49c59792a 100644 --- a/consensus/spos/consensusMessageValidator.go +++ b/consensus/spos/consensusMessageValidator.go @@ -122,12 +122,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", @@ -392,18 +386,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)) - } - - 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/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..fba74a94674 100644 --- a/factory/peerSignatureHandler/peerSignatureHandler.go +++ b/factory/peerSignatureHandler/peerSignatureHandler.go @@ -49,6 +49,10 @@ 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 8156b64c8eb..8d0d99d5e5f 100644 --- a/keysManagement/managedPeersHolder.go +++ b/keysManagement/managedPeersHolder.go @@ -134,16 +134,8 @@ 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)) - } - - publicKey := privateKey.GeneratePublic() - publicKeyBytes, err := publicKey.ToByteArray() - if err != nil { - return fmt.Errorf("%w for provided bytes %s", err, hex.EncodeToString(privateKeyBytes)) - } + sk, _ := holder.keyGenerator.GeneratePair() + publicKeyBytes := privateKeyBytes p2pPrivateKey, p2pPublicKey := holder.p2pKeyGenerator.GeneratePair() @@ -179,7 +171,7 @@ func (holder *managedPeersHolder) AddManagedPeer(privateKeyBytes []byte) error { pInfo.handler = common.NewRedundancyHandler() pInfo.pid = pid pInfo.p2pPrivateKeyBytes = p2pPrivateKeyBytes - pInfo.privateKey = privateKey + pInfo.privateKey = sk holder.data[string(publicKeyBytes)] = pInfo holder.pids[pid] = struct{}{} diff --git a/node/node.go b/node/node.go index 38b00841d2a..230eb4ac6ff 100644 --- a/node/node.go +++ b/node/node.go @@ -727,7 +727,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 b39787c7a96..67499767b83 100644 --- a/process/block/headerValidator.go +++ b/process/block/headerValidator.go @@ -78,15 +78,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 fb53f1207d7..dd109c0268f 100644 --- a/process/block/metablock.go +++ b/process/block/metablock.go @@ -5,6 +5,8 @@ import ( "encoding/hex" "fmt" "math/big" + "strconv" + "strings" "sync" "time" @@ -22,10 +24,13 @@ 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" logger "github.com/multiversx/mx-chain-logger-go" ) const firstHeaderNonce = uint64(1) +const minRoundModulus = uint64(4) var _ process.BlockProcessor = (*metaProcessor)(nil) @@ -44,6 +49,9 @@ type metaProcessor struct { shardBlockFinality uint32 chRcvAllHdrs chan bool headersCounter *headersCounter + nrEpochsChanges int + roundsModulus uint64 + shouldStartBootstrap bool } // NewMetaProcessor creates a new metaProcessor object @@ -179,6 +187,9 @@ func NewMetaProcessor(arguments ArgMetaProcessor) (*metaProcessor, error) { mp.shardsHeadersNonce = &sync.Map{} + mp.nrEpochsChanges = 0 + mp.roundsModulus = 20 + return &mp, nil } @@ -407,6 +418,8 @@ func (mp *metaProcessor) ProcessBlock( return err } + mp.ForceStart(header) + return nil } @@ -771,6 +784,8 @@ func (mp *metaProcessor) CreateBlock( mp.requestHandler.SetEpoch(metaHdr.GetEpoch()) + mp.ForceStart(metaHdr) + return metaHdr, body, nil } @@ -2545,3 +2560,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/heartbeat/interceptedPeerAuthentication.go b/process/heartbeat/interceptedPeerAuthentication.go index a10e5e6dd8d..2d584811b5c 100644 --- a/process/heartbeat/interceptedPeerAuthentication.go +++ b/process/heartbeat/interceptedPeerAuthentication.go @@ -135,24 +135,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/transaction/baseProcess.go b/process/transaction/baseProcess.go index 0433f8a0f50..cb8407f9491 100644 --- a/process/transaction/baseProcess.go +++ b/process/transaction/baseProcess.go @@ -383,6 +383,11 @@ 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 {