diff --git a/node/transaction.go b/node/transaction.go index 2784d6e63..e426a9572 100644 --- a/node/transaction.go +++ b/node/transaction.go @@ -528,7 +528,7 @@ func (localNode *LocalNode) requestSignatureChainTransaction(neighbor *RemoteNod return nil, err } - porPkg, err := por.NewPorPackage(txn, false) + porPkg, err := por.NewPorPackage(txn) if err != nil { return nil, fmt.Errorf("create por package from txn error: %v", err) } diff --git a/por/minercache.go b/por/minercache.go index 34c6dde70..eb5470fd6 100644 --- a/por/minercache.go +++ b/por/minercache.go @@ -3,7 +3,6 @@ package por import ( "sort" "sync" - "time" "github.com/nknorg/nkn/v2/common" "github.com/nknorg/nkn/v2/config" @@ -21,8 +20,8 @@ type RecentMiner map[string]int type SkipMiner [][]byte func init() { - recentMinerCache = common.NewGoCache(5*time.Minute, time.Minute) - skipMinerCache = common.NewGoCache(5*time.Minute, time.Minute) + recentMinerCache = common.NewGoCache(10*config.ConsensusDuration, config.ConsensusDuration) + skipMinerCache = common.NewGoCache(10*config.ConsensusDuration, config.ConsensusDuration) } func GetRecentMiner(blockHash []byte) (RecentMiner, error) { diff --git a/por/porpackage.go b/por/porpackage.go index 2681030a4..15248a44d 100644 --- a/por/porpackage.go +++ b/por/porpackage.go @@ -54,7 +54,7 @@ func (c PorPackages) Less(i, j int) bool { return false } -func NewPorPackage(txn *transaction.Transaction, shouldVerify bool) (*PorPackage, error) { +func NewPorPackage(txn *transaction.Transaction) (*PorPackage, error) { if txn.UnsignedTx.Payload.Type != pb.PayloadType_SIG_CHAIN_TXN_TYPE { return nil, errors.New("Transaction type should be sigchain") } @@ -96,16 +96,9 @@ func NewPorPackage(txn *transaction.Transaction, shouldVerify bool) (*PorPackage return nil, err } - if shouldVerify { - err = VerifyID(sigChain, height) - if err != nil { - return nil, err - } - - err = VerifySigChain(sigChain, height) - if err != nil { - return nil, err - } + err = VerifySigChainLight(sigChain, height) + if err != nil { + return nil, err } txHash := txn.Hash() diff --git a/por/porserver.go b/por/porserver.go index c35c90a6a..99b0c365e 100644 --- a/por/porserver.go +++ b/por/porserver.go @@ -411,7 +411,7 @@ func VerifyID(sc *pb.SigChain, height uint32) error { } func (ps *PorServer) AddSigChainFromTx(txn *transaction.Transaction, currentHeight uint32) (*PorPackage, error) { - porPkg, err := NewPorPackage(txn, false) + porPkg, err := NewPorPackage(txn) if err != nil { return nil, err } @@ -428,7 +428,7 @@ func (ps *PorServer) AddSigChainFromTx(txn *transaction.Transaction, currentHeig return nil, err } - err = VerifySigChain(porPkg.SigChain, porPkg.Height) + err = VerifySigChainSignatures(porPkg.SigChain) if err != nil { return nil, err } diff --git a/por/sigchain.go b/por/sigchain.go index a913a181f..8882e1bfc 100644 --- a/por/sigchain.go +++ b/por/sigchain.go @@ -15,7 +15,9 @@ import ( "github.com/nknorg/nnet/overlay/chord" ) -func VerifySigChain(sc *pb.SigChain, height uint32) error { +// VerifySigChainLight performs light-weighted sigchain verification without +// verifying signature (CPU intensive) and ID (IO intensive). +func VerifySigChainLight(sc *pb.SigChain, height uint32) error { if err := VerifySigChainMeta(sc, height); err != nil { return err } @@ -24,10 +26,6 @@ func VerifySigChain(sc *pb.SigChain, height uint32) error { return err } - if err := VerifySigChainSignatures(sc); err != nil { - return err - } - return nil }