Skip to content

Commit

Permalink
Add consensus test and commment for graph_weight
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinlesceller committed Feb 20, 2020
1 parent 7cdb5b7 commit 7bef227
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 6 additions & 3 deletions core/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,18 @@ const DifficultyDampFactor uint64 = 3
// ARScaleDampFactor is the dampening factor to use for AR scale calculation.
const ARScaleDampFactor uint64 = 13

// GraphWeight is a weight of a graph as number of siphash bits defining the graph
// Must be made dependent on height to phase out smaller size over the years
// This can wait until end of 2019 at latest
// GraphWeight compute weight of a graph as number of siphash bits defining the graph
// Must be made dependent on height to phase out C31 in early 2020
// Later phase outs are on hold for now
func GraphWeight(chainType ChainType, height uint64, edgeBits uint8) uint64 {
xprEdgeBits := uint64(edgeBits)
expiryHeight := YearHeight
if edgeBits == 31 && height >= expiryHeight {
xprEdgeBits = saturatingSubUint64(xprEdgeBits, 1+(height-expiryHeight)/WeekHeight)
}
// For C31 xpr_edge_bits reaches 0 at height YEAR_HEIGHT + 30 * WEEK_HEIGHT
// 30 weeks after Jan 15, 2020 would be Aug 12, 2020

return (uint64(2) << uint64(edgeBits-baseEdgeBits(chainType))) * xprEdgeBits
}

Expand Down
5 changes: 3 additions & 2 deletions core/consensus/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ func TestGraphWeight(t *testing.T) {
assert.Equal(t, GraphWeight(Mainnet, 2*YearHeight+WeekHeight, 32), uint64(512*32))
assert.Equal(t, GraphWeight(Mainnet, 2*YearHeight+WeekHeight, 31), uint64(0))
assert.Equal(t, GraphWeight(Mainnet, 2*YearHeight+30*WeekHeight, 32), uint64(512*32))
assert.Equal(t, GraphWeight(Mainnet, 2*YearHeight+31*WeekHeight, 32), uint64(512*32))
assert.Equal(t,
GraphWeight(Mainnet, 2*YearHeight+31*WeekHeight, 32), uint64(512*32))

// 3 years in, nothing changes
assert.Equal(t, GraphWeight(Mainnet, 3*YearHeight, 31), uint64(0))
assert.Equal(t, GraphWeight(Mainnet, 3*YearHeight, 32), uint64(512*32))
assert.Equal(t, GraphWeight(Mainnet, 3*YearHeight, 33), uint64(1024*33))

// 4 years in, 33 starts starts decreasing
// 4 years in, still on hold
assert.Equal(t, GraphWeight(Mainnet, 4*YearHeight, 31), uint64(0))
assert.Equal(t, GraphWeight(Mainnet, 4*YearHeight, 32), uint64(512*32))
assert.Equal(t, GraphWeight(Mainnet, 4*YearHeight, 33), uint64(1024*33))
Expand Down

0 comments on commit 7bef227

Please sign in to comment.