Skip to content

Commit

Permalink
sf latest release
Browse files Browse the repository at this point in the history
  • Loading branch information
miiu96 committed Jan 30, 2025
1 parent 02d8d81 commit 8da05ce
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 90 deletions.
2 changes: 1 addition & 1 deletion common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions consensus/spos/bls/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 0 additions & 18 deletions consensus/spos/consensusMessageValidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
}

Expand Down
36 changes: 6 additions & 30 deletions factory/crypto/cryptoComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 4 additions & 0 deletions factory/peerSignatureHandler/peerSignatureHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 3 additions & 11 deletions keysManagement/managedPeersHolder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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{}{}

Expand Down
2 changes: 1 addition & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 0 additions & 9 deletions process/block/headerValidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
77 changes: 77 additions & 0 deletions process/block/metablock.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"encoding/hex"
"fmt"
"math/big"
"strconv"
"strings"
"sync"
"time"

Expand All @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -179,6 +187,9 @@ func NewMetaProcessor(arguments ArgMetaProcessor) (*metaProcessor, error) {

mp.shardsHeadersNonce = &sync.Map{}

mp.nrEpochsChanges = 0
mp.roundsModulus = 20

return &mp, nil
}

Expand Down Expand Up @@ -407,6 +418,8 @@ func (mp *metaProcessor) ProcessBlock(
return err
}

mp.ForceStart(header)

return nil
}

Expand Down Expand Up @@ -771,6 +784,8 @@ func (mp *metaProcessor) CreateBlock(

mp.requestHandler.SetEpoch(metaHdr.GetEpoch())

mp.ForceStart(metaHdr)

return metaHdr, body, nil
}

Expand Down Expand Up @@ -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)
}
18 changes: 0 additions & 18 deletions process/heartbeat/interceptedPeerAuthentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions process/transaction/baseProcess.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8da05ce

Please sign in to comment.