mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-11-24 06:25:55 +00:00
[NOD-747] Change FinalityInterval to be 24 hours, isCurrent to be true if the DAG's time is less than 12 hours than the present, and change MaxInvPerMsg to be 1 << 17 (#625)
This commit is contained in:
parent
be556ada9b
commit
271bcedc19
@ -27,6 +27,8 @@ const (
|
|||||||
// maxOrphanBlocks is the maximum number of orphan blocks that can be
|
// maxOrphanBlocks is the maximum number of orphan blocks that can be
|
||||||
// queued.
|
// queued.
|
||||||
maxOrphanBlocks = 100
|
maxOrphanBlocks = 100
|
||||||
|
|
||||||
|
isDAGCurrentMaxDiff = 12 * time.Hour
|
||||||
)
|
)
|
||||||
|
|
||||||
// orphanBlock represents a block that we don't yet have the parent for. It
|
// orphanBlock represents a block that we don't yet have the parent for. It
|
||||||
@ -1274,8 +1276,8 @@ func (dag *BlockDAG) isCurrent() bool {
|
|||||||
} else {
|
} else {
|
||||||
dagTimestamp = selectedTip.timestamp
|
dagTimestamp = selectedTip.timestamp
|
||||||
}
|
}
|
||||||
minus24Hours := dag.AdjustedTime().Add(-24 * time.Hour).Unix()
|
dagTime := time.Unix(dagTimestamp, 0)
|
||||||
return dagTimestamp >= minus24Hours
|
return dag.AdjustedTime().Sub(dagTime) <= isDAGCurrentMaxDiff
|
||||||
}
|
}
|
||||||
|
|
||||||
// AdjustedTime returns the adjusted time according to
|
// AdjustedTime returns the adjusted time according to
|
||||||
|
|||||||
@ -938,7 +938,7 @@ func testFinalizeNodesBelowFinalityPoint(t *testing.T, deleteDiffData bool) {
|
|||||||
nodes := make([]*blockNode, 0, finalityInterval)
|
nodes := make([]*blockNode, 0, finalityInterval)
|
||||||
currentNode := dag.genesis
|
currentNode := dag.genesis
|
||||||
nodes = append(nodes, currentNode)
|
nodes = append(nodes, currentNode)
|
||||||
for i := 0; i <= finalityInterval*2; i++ {
|
for i := uint64(0); i <= finalityInterval*2; i++ {
|
||||||
currentNode = addNode(currentNode)
|
currentNode = addNode(currentNode)
|
||||||
nodes = append(nodes, currentNode)
|
nodes = append(nodes, currentNode)
|
||||||
}
|
}
|
||||||
@ -1084,3 +1084,18 @@ func TestDAGIndexFailedStatus(t *testing.T) {
|
|||||||
t.Fatalf("invalidBlockGrandChildNode status to have %b flags raised (got %b)", statusInvalidAncestor, invalidBlockGrandChildNode.status)
|
t.Fatalf("invalidBlockGrandChildNode status to have %b flags raised (got %b)", statusInvalidAncestor, invalidBlockGrandChildNode.status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIsDAGCurrentMaxDiff(t *testing.T) {
|
||||||
|
netParams := []*dagconfig.Params{
|
||||||
|
&dagconfig.MainnetParams,
|
||||||
|
&dagconfig.TestnetParams,
|
||||||
|
&dagconfig.DevnetParams,
|
||||||
|
&dagconfig.RegressionNetParams,
|
||||||
|
&dagconfig.SimnetParams,
|
||||||
|
}
|
||||||
|
for _, params := range netParams {
|
||||||
|
if params.TargetTimePerBlock*time.Duration(params.FinalityInterval) < isDAGCurrentMaxDiff {
|
||||||
|
t.Errorf("in %s, a DAG can be considered current even if it's below the finality point", params.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -73,7 +73,7 @@ func TestFinality(t *testing.T) {
|
|||||||
currentNode := genesis
|
currentNode := genesis
|
||||||
|
|
||||||
// First we build a chain of params.FinalityInterval blocks for future use
|
// First we build a chain of params.FinalityInterval blocks for future use
|
||||||
for i := 0; i < params.FinalityInterval; i++ {
|
for i := uint64(0); i < params.FinalityInterval; i++ {
|
||||||
currentNode, err = buildNodeToDag([]*daghash.Hash{currentNode.Hash()})
|
currentNode, err = buildNodeToDag([]*daghash.Hash{currentNode.Hash()})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("TestFinality: buildNodeToDag unexpectedly returned an error: %v", err)
|
t.Fatalf("TestFinality: buildNodeToDag unexpectedly returned an error: %v", err)
|
||||||
@ -85,7 +85,7 @@ func TestFinality(t *testing.T) {
|
|||||||
// Now we build a new chain of 2 * params.FinalityInterval blocks, pointed to genesis, and
|
// Now we build a new chain of 2 * params.FinalityInterval blocks, pointed to genesis, and
|
||||||
// we expect the block with height 1 * params.FinalityInterval to be the last finality point
|
// we expect the block with height 1 * params.FinalityInterval to be the last finality point
|
||||||
currentNode = genesis
|
currentNode = genesis
|
||||||
for i := 0; i < params.FinalityInterval; i++ {
|
for i := uint64(0); i < params.FinalityInterval; i++ {
|
||||||
currentNode, err = buildNodeToDag([]*daghash.Hash{currentNode.Hash()})
|
currentNode, err = buildNodeToDag([]*daghash.Hash{currentNode.Hash()})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("TestFinality: buildNodeToDag unexpectedly returned an error: %v", err)
|
t.Fatalf("TestFinality: buildNodeToDag unexpectedly returned an error: %v", err)
|
||||||
@ -94,7 +94,7 @@ func TestFinality(t *testing.T) {
|
|||||||
|
|
||||||
expectedFinalityPoint := currentNode
|
expectedFinalityPoint := currentNode
|
||||||
|
|
||||||
for i := 0; i < params.FinalityInterval; i++ {
|
for i := uint64(0); i < params.FinalityInterval; i++ {
|
||||||
currentNode, err = buildNodeToDag([]*daghash.Hash{currentNode.Hash()})
|
currentNode, err = buildNodeToDag([]*daghash.Hash{currentNode.Hash()})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("TestFinality: buildNodeToDag unexpectedly returned an error: %v", err)
|
t.Fatalf("TestFinality: buildNodeToDag unexpectedly returned an error: %v", err)
|
||||||
@ -167,9 +167,17 @@ func TestFinality(t *testing.T) {
|
|||||||
// a getblocks message it should always be able to send
|
// a getblocks message it should always be able to send
|
||||||
// all the necessary invs.
|
// all the necessary invs.
|
||||||
func TestFinalityInterval(t *testing.T) {
|
func TestFinalityInterval(t *testing.T) {
|
||||||
params := dagconfig.SimnetParams
|
netParams := []*dagconfig.Params{
|
||||||
|
&dagconfig.MainnetParams,
|
||||||
|
&dagconfig.TestnetParams,
|
||||||
|
&dagconfig.DevnetParams,
|
||||||
|
&dagconfig.RegressionNetParams,
|
||||||
|
&dagconfig.SimnetParams,
|
||||||
|
}
|
||||||
|
for _, params := range netParams {
|
||||||
if params.FinalityInterval > wire.MaxInvPerMsg {
|
if params.FinalityInterval > wire.MaxInvPerMsg {
|
||||||
t.Errorf("dagconfig.SimnetParams.FinalityInterval should be lower or equal to wire.MaxInvPerMsg")
|
t.Errorf("FinalityInterval in %s should be lower or equal to wire.MaxInvPerMsg", params.Name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -47,9 +47,14 @@ var (
|
|||||||
devnetPowMax = new(big.Int).Sub(new(big.Int).Lsh(bigOne, 239), bigOne)
|
devnetPowMax = new(big.Int).Sub(new(big.Int).Lsh(bigOne, 239), bigOne)
|
||||||
)
|
)
|
||||||
|
|
||||||
const ghostdagK = 10
|
const (
|
||||||
const difficultyAdjustmentWindowSize = 2640
|
ghostdagK = 10
|
||||||
const timestampDeviationTolerance = 132
|
difficultyAdjustmentWindowSize = 2640
|
||||||
|
timestampDeviationTolerance = 132
|
||||||
|
finalityDuration = 24 * time.Hour
|
||||||
|
targetTimePerBlock = 1 * time.Second
|
||||||
|
finalityInterval = uint64(finalityDuration / targetTimePerBlock)
|
||||||
|
)
|
||||||
|
|
||||||
// ConsensusDeployment defines details related to a specific consensus rule
|
// ConsensusDeployment defines details related to a specific consensus rule
|
||||||
// change that is voted in. This is part of BIP0009.
|
// change that is voted in. This is part of BIP0009.
|
||||||
@ -132,7 +137,7 @@ type Params struct {
|
|||||||
TargetTimePerBlock time.Duration
|
TargetTimePerBlock time.Duration
|
||||||
|
|
||||||
// FinalityInterval is the interval that determines the finality window of the DAG.
|
// FinalityInterval is the interval that determines the finality window of the DAG.
|
||||||
FinalityInterval int
|
FinalityInterval uint64
|
||||||
|
|
||||||
// TimestampDeviationTolerance is the maximum offset a block timestamp
|
// TimestampDeviationTolerance is the maximum offset a block timestamp
|
||||||
// is allowed to be in the future before it gets delayed
|
// is allowed to be in the future before it gets delayed
|
||||||
@ -195,8 +200,8 @@ var MainnetParams = Params{
|
|||||||
PowMax: mainPowMax,
|
PowMax: mainPowMax,
|
||||||
BlockCoinbaseMaturity: 100,
|
BlockCoinbaseMaturity: 100,
|
||||||
SubsidyReductionInterval: 210000,
|
SubsidyReductionInterval: 210000,
|
||||||
TargetTimePerBlock: time.Second * 1, // 1 second
|
TargetTimePerBlock: targetTimePerBlock,
|
||||||
FinalityInterval: 1000,
|
FinalityInterval: finalityInterval,
|
||||||
DifficultyAdjustmentWindowSize: difficultyAdjustmentWindowSize,
|
DifficultyAdjustmentWindowSize: difficultyAdjustmentWindowSize,
|
||||||
TimestampDeviationTolerance: timestampDeviationTolerance,
|
TimestampDeviationTolerance: timestampDeviationTolerance,
|
||||||
|
|
||||||
@ -252,8 +257,8 @@ var RegressionNetParams = Params{
|
|||||||
PowMax: regressionPowMax,
|
PowMax: regressionPowMax,
|
||||||
BlockCoinbaseMaturity: 100,
|
BlockCoinbaseMaturity: 100,
|
||||||
SubsidyReductionInterval: 150,
|
SubsidyReductionInterval: 150,
|
||||||
TargetTimePerBlock: time.Second * 1, // 1 second
|
TargetTimePerBlock: targetTimePerBlock,
|
||||||
FinalityInterval: 1000,
|
FinalityInterval: finalityInterval,
|
||||||
DifficultyAdjustmentWindowSize: difficultyAdjustmentWindowSize,
|
DifficultyAdjustmentWindowSize: difficultyAdjustmentWindowSize,
|
||||||
TimestampDeviationTolerance: timestampDeviationTolerance,
|
TimestampDeviationTolerance: timestampDeviationTolerance,
|
||||||
|
|
||||||
@ -307,8 +312,8 @@ var TestnetParams = Params{
|
|||||||
PowMax: testnetPowMax,
|
PowMax: testnetPowMax,
|
||||||
BlockCoinbaseMaturity: 100,
|
BlockCoinbaseMaturity: 100,
|
||||||
SubsidyReductionInterval: 210000,
|
SubsidyReductionInterval: 210000,
|
||||||
TargetTimePerBlock: time.Second * 1, // 1 second
|
TargetTimePerBlock: targetTimePerBlock,
|
||||||
FinalityInterval: 1000,
|
FinalityInterval: finalityInterval,
|
||||||
DifficultyAdjustmentWindowSize: difficultyAdjustmentWindowSize,
|
DifficultyAdjustmentWindowSize: difficultyAdjustmentWindowSize,
|
||||||
TimestampDeviationTolerance: timestampDeviationTolerance,
|
TimestampDeviationTolerance: timestampDeviationTolerance,
|
||||||
|
|
||||||
@ -368,8 +373,8 @@ var SimnetParams = Params{
|
|||||||
PowMax: simnetPowMax,
|
PowMax: simnetPowMax,
|
||||||
BlockCoinbaseMaturity: 100,
|
BlockCoinbaseMaturity: 100,
|
||||||
SubsidyReductionInterval: 210000,
|
SubsidyReductionInterval: 210000,
|
||||||
TargetTimePerBlock: time.Second * 1, // 1 second
|
TargetTimePerBlock: targetTimePerBlock,
|
||||||
FinalityInterval: 1000,
|
FinalityInterval: finalityInterval,
|
||||||
DifficultyAdjustmentWindowSize: difficultyAdjustmentWindowSize,
|
DifficultyAdjustmentWindowSize: difficultyAdjustmentWindowSize,
|
||||||
TimestampDeviationTolerance: timestampDeviationTolerance,
|
TimestampDeviationTolerance: timestampDeviationTolerance,
|
||||||
|
|
||||||
@ -421,8 +426,8 @@ var DevnetParams = Params{
|
|||||||
PowMax: devnetPowMax,
|
PowMax: devnetPowMax,
|
||||||
BlockCoinbaseMaturity: 100,
|
BlockCoinbaseMaturity: 100,
|
||||||
SubsidyReductionInterval: 210000,
|
SubsidyReductionInterval: 210000,
|
||||||
TargetTimePerBlock: time.Second * 1, // 1 second
|
TargetTimePerBlock: targetTimePerBlock,
|
||||||
FinalityInterval: 1000,
|
FinalityInterval: finalityInterval,
|
||||||
DifficultyAdjustmentWindowSize: difficultyAdjustmentWindowSize,
|
DifficultyAdjustmentWindowSize: difficultyAdjustmentWindowSize,
|
||||||
TimestampDeviationTolerance: timestampDeviationTolerance,
|
TimestampDeviationTolerance: timestampDeviationTolerance,
|
||||||
|
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
// MaxInvPerMsg is the maximum number of inventory vectors that can be in a
|
// MaxInvPerMsg is the maximum number of inventory vectors that can be in a
|
||||||
// single kaspa inv message.
|
// single kaspa inv message.
|
||||||
MaxInvPerMsg = 1 << 16
|
MaxInvPerMsg = 1 << 17
|
||||||
|
|
||||||
// MaxSyncBlockInvPerGetDataMsg is the maximum number of sync block inventory
|
// MaxSyncBlockInvPerGetDataMsg is the maximum number of sync block inventory
|
||||||
// vectors that can be in a single getData message.
|
// vectors that can be in a single getData message.
|
||||||
|
|||||||
@ -28,7 +28,7 @@ func TestGetData(t *testing.T) {
|
|||||||
|
|
||||||
// Ensure max payload is expected value for latest protocol version.
|
// Ensure max payload is expected value for latest protocol version.
|
||||||
// Num inventory vectors (varInt) + max allowed inventory vectors.
|
// Num inventory vectors (varInt) + max allowed inventory vectors.
|
||||||
wantPayload := uint32(2359305)
|
wantPayload := uint32(4718601)
|
||||||
maxPayload := msg.MaxPayloadLength(pver)
|
maxPayload := msg.MaxPayloadLength(pver)
|
||||||
if maxPayload != wantPayload {
|
if maxPayload != wantPayload {
|
||||||
t.Errorf("MaxPayloadLength: wrong max payload length for "+
|
t.Errorf("MaxPayloadLength: wrong max payload length for "+
|
||||||
|
|||||||
@ -28,7 +28,7 @@ func TestInv(t *testing.T) {
|
|||||||
|
|
||||||
// Ensure max payload is expected value for latest protocol version.
|
// Ensure max payload is expected value for latest protocol version.
|
||||||
// Num inventory vectors (varInt) + max allowed inventory vectors.
|
// Num inventory vectors (varInt) + max allowed inventory vectors.
|
||||||
wantPayload := uint32(2359305)
|
wantPayload := uint32(4718601)
|
||||||
maxPayload := msg.MaxPayloadLength(pver)
|
maxPayload := msg.MaxPayloadLength(pver)
|
||||||
if maxPayload != wantPayload {
|
if maxPayload != wantPayload {
|
||||||
t.Errorf("MaxPayloadLength: wrong max payload length for "+
|
t.Errorf("MaxPayloadLength: wrong max payload length for "+
|
||||||
|
|||||||
@ -28,7 +28,7 @@ func TestNotFound(t *testing.T) {
|
|||||||
|
|
||||||
// Ensure max payload is expected value for latest protocol version.
|
// Ensure max payload is expected value for latest protocol version.
|
||||||
// Num inventory vectors (varInt) + max allowed inventory vectors.
|
// Num inventory vectors (varInt) + max allowed inventory vectors.
|
||||||
wantPayload := uint32(2359305)
|
wantPayload := uint32(4718601)
|
||||||
maxPayload := msg.MaxPayloadLength(pver)
|
maxPayload := msg.MaxPayloadLength(pver)
|
||||||
if maxPayload != wantPayload {
|
if maxPayload != wantPayload {
|
||||||
t.Errorf("MaxPayloadLength: wrong max payload length for "+
|
t.Errorf("MaxPayloadLength: wrong max payload length for "+
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user