Split monero from p2pool hardforks
This commit is contained in:
parent
3e689ae7be
commit
fe5c673125
|
@ -15,6 +15,8 @@ func GetBaseReward(alreadyGeneratedCounts uint64) uint64 {
|
|||
return result
|
||||
}
|
||||
|
||||
// GetBlockReward
|
||||
// Taken from https://github.com/monero-project/monero/blob/b0bf49a65a38ceb1acfbc8e17f40e63383ac140d/src/cryptonote_basic/cryptonote_basic_impl.cpp#L83
|
||||
func GetBlockReward(medianWeight, currentBlockWeight, alreadyGeneratedCoins uint64, version uint8) (reward uint64) {
|
||||
const DIFFICULTY_TARGET_V1 = 60 // seconds - before first fork
|
||||
const DIFFICULTY_TARGET_V2 = 120 // seconds
|
||||
|
@ -40,6 +42,7 @@ func GetBlockReward(medianWeight, currentBlockWeight, alreadyGeneratedCoins uint
|
|||
}
|
||||
|
||||
fullRewardZone := func(version uint8) uint64 {
|
||||
// From get_min_block_weight()
|
||||
if version < 2 {
|
||||
return CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package monero
|
||||
|
||||
const (
|
||||
BlockTime = 60 * 2
|
||||
HardForkViewTagsVersion = 15
|
||||
HardForkSupportedVersion = 16
|
||||
BlockTime = 60 * 2
|
||||
|
||||
TransactionUnlockTime = 10
|
||||
MinerRewardUnlockTime = 60
|
||||
|
|
142
monero/hardfork.go
Normal file
142
monero/hardfork.go
Normal file
|
@ -0,0 +1,142 @@
|
|||
package monero
|
||||
|
||||
const (
|
||||
HardForkViewTagsVersion = 15
|
||||
HardForkSupportedVersion = 16
|
||||
)
|
||||
|
||||
type HardFork struct {
|
||||
// Version Numeric epoch of the version
|
||||
Version uint8 `json:"version"`
|
||||
// Time Block height at which the hardfork occurs (Monero)
|
||||
Height uint64 `json:"height"`
|
||||
// Threshold Not used currently
|
||||
Threshold uint8 `json:"threshold"`
|
||||
// Time Unix timestamp at which the hardfork occurs (p2pool), or when it happened (Monero)
|
||||
Time uint64 `json:"time"`
|
||||
}
|
||||
|
||||
// List of historical Monero hardforks and future ones
|
||||
// Taken from https://github.com/monero-project/monero/blob/5b4fea72cf8b5853d33d1765d4d00cf5608adcb3/src/hardforks/hardforks.cpp
|
||||
|
||||
var mainNetHardForks = []HardFork{
|
||||
// version 1 from the start of the blockchain
|
||||
{1, 1, 0, 1341378000},
|
||||
|
||||
// version 2 starts from block 1009827, which is on or around the 20th of March, 2016. Fork time finalised on 2015-09-20. No fork voting occurs for the v2 fork.
|
||||
{2, 1009827, 0, 1442763710},
|
||||
|
||||
// version 3 starts from block 1141317, which is on or around the 24th of September, 2016. Fork time finalised on 2016-03-21.
|
||||
{3, 1141317, 0, 1458558528},
|
||||
|
||||
// version 4 starts from block 1220516, which is on or around the 5th of January, 2017. Fork time finalised on 2016-09-18.
|
||||
{4, 1220516, 0, 1483574400},
|
||||
|
||||
// version 5 starts from block 1288616, which is on or around the 15th of April, 2017. Fork time finalised on 2017-03-14.
|
||||
{5, 1288616, 0, 1489520158},
|
||||
|
||||
// version 6 starts from block 1400000, which is on or around the 16th of September, 2017. Fork time finalised on 2017-08-18.
|
||||
{6, 1400000, 0, 1503046577},
|
||||
|
||||
// version 7 starts from block 1546000, which is on or around the 6th of April, 2018. Fork time finalised on 2018-03-17.
|
||||
{7, 1546000, 0, 1521303150},
|
||||
|
||||
// version 8 starts from block 1685555, which is on or around the 18th of October, 2018. Fork time finalised on 2018-09-02.
|
||||
{8, 1685555, 0, 1535889547},
|
||||
|
||||
// version 9 starts from block 1686275, which is on or around the 19th of October, 2018. Fork time finalised on 2018-09-02.
|
||||
{9, 1686275, 0, 1535889548},
|
||||
|
||||
// version 10 starts from block 1788000, which is on or around the 9th of March, 2019. Fork time finalised on 2019-02-10.
|
||||
{10, 1788000, 0, 1549792439},
|
||||
|
||||
// version 11 starts from block 1788720, which is on or around the 10th of March, 2019. Fork time finalised on 2019-02-15.
|
||||
{11, 1788720, 0, 1550225678},
|
||||
|
||||
// version 12 starts from block 1978433, which is on or around the 30th of November, 2019. Fork time finalised on 2019-10-18.
|
||||
{12, 1978433, 0, 1571419280},
|
||||
|
||||
{13, 2210000, 0, 1598180817},
|
||||
{14, 2210720, 0, 1598180818},
|
||||
|
||||
{15, 2688888, 0, 1656629117},
|
||||
{16, 2689608, 0, 1656629118},
|
||||
}
|
||||
|
||||
var testNetHardForks = []HardFork{
|
||||
// version 1 from the start of the blockchain
|
||||
{1, 1, 0, 1341378000},
|
||||
|
||||
// version 2 starts from block 624634, which is on or around the 23rd of November, 2015. Fork time finalised on 2015-11-20. No fork voting occurs for the v2 fork.
|
||||
{2, 624634, 0, 1445355000},
|
||||
|
||||
// versions 3-5 were passed in rapid succession from September 18th, 2016
|
||||
{3, 800500, 0, 1472415034},
|
||||
{4, 801219, 0, 1472415035},
|
||||
{5, 802660, 0, 1472415036 + 86400*180}, // add 5 months on testnet to shut the update warning up since there's a large gap to v6
|
||||
|
||||
{6, 971400, 0, 1501709789},
|
||||
{7, 1057027, 0, 1512211236},
|
||||
{8, 1057058, 0, 1533211200},
|
||||
{9, 1057778, 0, 1533297600},
|
||||
{10, 1154318, 0, 1550153694},
|
||||
{11, 1155038, 0, 1550225678},
|
||||
{12, 1308737, 0, 1569582000},
|
||||
{13, 1543939, 0, 1599069376},
|
||||
{14, 1544659, 0, 1599069377},
|
||||
{15, 1982800, 0, 1652727000},
|
||||
{16, 1983520, 0, 1652813400},
|
||||
}
|
||||
|
||||
var stageNetHardForks = []HardFork{
|
||||
// version 1 from the start of the blockchain
|
||||
{1, 1, 0, 1341378000},
|
||||
|
||||
// versions 2-7 in rapid succession from March 13th, 2018
|
||||
{2, 32000, 0, 1521000000},
|
||||
{3, 33000, 0, 1521120000},
|
||||
{4, 34000, 0, 1521240000},
|
||||
{5, 35000, 0, 1521360000},
|
||||
{6, 36000, 0, 1521480000},
|
||||
{7, 37000, 0, 1521600000},
|
||||
{8, 176456, 0, 1537821770},
|
||||
{9, 177176, 0, 1537821771},
|
||||
{10, 269000, 0, 1550153694},
|
||||
{11, 269720, 0, 1550225678},
|
||||
{12, 454721, 0, 1571419280},
|
||||
{13, 675405, 0, 1598180817},
|
||||
{14, 676125, 0, 1598180818},
|
||||
{15, 1151000, 0, 1656629117},
|
||||
{16, 1151720, 0, 1656629118},
|
||||
}
|
||||
|
||||
func NetworkHardFork(network uint8) []HardFork {
|
||||
switch network {
|
||||
case MainNetwork:
|
||||
return mainNetHardForks
|
||||
case TestNetwork:
|
||||
return testNetHardForks
|
||||
case StageNetwork:
|
||||
return stageNetHardForks
|
||||
default:
|
||||
panic("invalid network type for hardfork")
|
||||
}
|
||||
}
|
||||
|
||||
func NetworkMajorVersion(network uint8, height uint64) uint8 {
|
||||
hardForks := NetworkHardFork(network)
|
||||
|
||||
if len(hardForks) == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
result := hardForks[0].Version
|
||||
|
||||
for _, f := range hardForks[1:] {
|
||||
if height < f.Height {
|
||||
break
|
||||
}
|
||||
result = f.Version
|
||||
}
|
||||
return result
|
||||
}
|
41
monero/hardfork_test.go
Normal file
41
monero/hardfork_test.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package monero
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNetworkHardForkSupportedMainnet(t *testing.T) {
|
||||
hardForks := NetworkHardFork(MainNetwork)
|
||||
f := hardForks[len(hardForks)-1]
|
||||
|
||||
if f.Version < HardForkSupportedVersion {
|
||||
t.Fatalf("supported version %d greater than latest mainnet hardfork, last %d", HardForkSupportedVersion, f.Version)
|
||||
}
|
||||
if f.Version > HardForkSupportedVersion {
|
||||
t.Fatalf("supported version %d smaller than latest mainnet hardfork, last %d", HardForkSupportedVersion, f.Version)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNetworkHardForkSupportedTestnet(t *testing.T) {
|
||||
hardForks := NetworkHardFork(TestNetwork)
|
||||
f := hardForks[len(hardForks)-1]
|
||||
|
||||
if f.Version < HardForkSupportedVersion {
|
||||
t.Fatalf("supported version %d greater than latest testnet hardfork, last %d", HardForkSupportedVersion, f.Version)
|
||||
}
|
||||
if f.Version > HardForkSupportedVersion {
|
||||
t.Fatalf("supported version %d smaller than latest testnet hardfork, last %d", HardForkSupportedVersion, f.Version)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNetworkHardForkSupportedStagenet(t *testing.T) {
|
||||
hardForks := NetworkHardFork(StageNetwork)
|
||||
f := hardForks[len(hardForks)-1]
|
||||
|
||||
if f.Version < HardForkSupportedVersion {
|
||||
t.Fatalf("supported version %d greater than latest stagenet hardfork, last %d", HardForkSupportedVersion, f.Version)
|
||||
}
|
||||
if f.Version > HardForkSupportedVersion {
|
||||
t.Fatalf("supported version %d smaller than latest stagenet hardfork, last %d", HardForkSupportedVersion, f.Version)
|
||||
}
|
||||
}
|
|
@ -56,6 +56,14 @@ func (n NetworkType) AddressNetwork() (uint8, error) {
|
|||
return 0, errors.New("unknown network")
|
||||
}
|
||||
|
||||
func (n NetworkType) MustAddressNetwork() uint8 {
|
||||
network, err := n.AddressNetwork()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return network
|
||||
}
|
||||
|
||||
func (n NetworkType) MarshalJSON() ([]byte, error) {
|
||||
return []byte("\"" + n.String() + "\""), nil
|
||||
}
|
||||
|
@ -98,7 +106,7 @@ type Consensus struct {
|
|||
// HardFork optional hardfork information for p2pool
|
||||
// If empty it will be filled with the default hardfork list to the corresponding NetworkType
|
||||
// Note: this is not supported by p2pool itself
|
||||
HardForks []HardFork `json:"hard_forks,omitempty"`
|
||||
HardForks []monero.HardFork `json:"hard_forks,omitempty"`
|
||||
|
||||
hasher randomx.Hasher
|
||||
|
||||
|
|
|
@ -1,110 +1,20 @@
|
|||
package sidechain
|
||||
|
||||
type HardFork struct {
|
||||
Version uint8 `json:"version"`
|
||||
Height uint64 `json:"height"`
|
||||
Threshold uint8 `json:"threshold"`
|
||||
Time uint64 `json:"time"`
|
||||
}
|
||||
import (
|
||||
"fmt"
|
||||
"git.gammaspectra.live/P2Pool/consensus/v3/monero"
|
||||
)
|
||||
|
||||
var mainNetHardForks = []HardFork{
|
||||
// version 1 from the start of the blockchain
|
||||
{1, 1, 0, 1341378000},
|
||||
|
||||
// version 2 starts from block 1009827, which is on or around the 20th of March, 2016. Fork time finalised on 2015-09-20. No fork voting occurs for the v2 fork.
|
||||
{2, 1009827, 0, 1442763710},
|
||||
|
||||
// version 3 starts from block 1141317, which is on or around the 24th of September, 2016. Fork time finalised on 2016-03-21.
|
||||
{3, 1141317, 0, 1458558528},
|
||||
|
||||
// version 4 starts from block 1220516, which is on or around the 5th of January, 2017. Fork time finalised on 2016-09-18.
|
||||
{4, 1220516, 0, 1483574400},
|
||||
|
||||
// version 5 starts from block 1288616, which is on or around the 15th of April, 2017. Fork time finalised on 2017-03-14.
|
||||
{5, 1288616, 0, 1489520158},
|
||||
|
||||
// version 6 starts from block 1400000, which is on or around the 16th of September, 2017. Fork time finalised on 2017-08-18.
|
||||
{6, 1400000, 0, 1503046577},
|
||||
|
||||
// version 7 starts from block 1546000, which is on or around the 6th of April, 2018. Fork time finalised on 2018-03-17.
|
||||
{7, 1546000, 0, 1521303150},
|
||||
|
||||
// version 8 starts from block 1685555, which is on or around the 18th of October, 2018. Fork time finalised on 2018-09-02.
|
||||
{8, 1685555, 0, 1535889547},
|
||||
|
||||
// version 9 starts from block 1686275, which is on or around the 19th of October, 2018. Fork time finalised on 2018-09-02.
|
||||
{9, 1686275, 0, 1535889548},
|
||||
|
||||
// version 10 starts from block 1788000, which is on or around the 9th of March, 2019. Fork time finalised on 2019-02-10.
|
||||
{10, 1788000, 0, 1549792439},
|
||||
|
||||
// version 11 starts from block 1788720, which is on or around the 10th of March, 2019. Fork time finalised on 2019-02-15.
|
||||
{11, 1788720, 0, 1550225678},
|
||||
|
||||
// version 12 starts from block 1978433, which is on or around the 30th of November, 2019. Fork time finalised on 2019-10-18.
|
||||
{12, 1978433, 0, 1571419280},
|
||||
|
||||
{13, 2210000, 0, 1598180817},
|
||||
{14, 2210720, 0, 1598180818},
|
||||
|
||||
{15, 2688888, 0, 1656629117},
|
||||
{16, 2689608, 0, 1656629118},
|
||||
}
|
||||
|
||||
var testNetHardForks = []HardFork{
|
||||
// version 1 from the start of the blockchain
|
||||
{1, 1, 0, 1341378000},
|
||||
|
||||
// version 2 starts from block 624634, which is on or around the 23rd of November, 2015. Fork time finalised on 2015-11-20. No fork voting occurs for the v2 fork.
|
||||
{2, 624634, 0, 1445355000},
|
||||
|
||||
// versions 3-5 were passed in rapid succession from September 18th, 2016
|
||||
{3, 800500, 0, 1472415034},
|
||||
{4, 801219, 0, 1472415035},
|
||||
{5, 802660, 0, 1472415036 + 86400*180}, // add 5 months on testnet to shut the update warning up since there's a large gap to v6
|
||||
|
||||
{6, 971400, 0, 1501709789},
|
||||
{7, 1057027, 0, 1512211236},
|
||||
{8, 1057058, 0, 1533211200},
|
||||
{9, 1057778, 0, 1533297600},
|
||||
{10, 1154318, 0, 1550153694},
|
||||
{11, 1155038, 0, 1550225678},
|
||||
{12, 1308737, 0, 1569582000},
|
||||
{13, 1543939, 0, 1599069376},
|
||||
{14, 1544659, 0, 1599069377},
|
||||
{15, 1982800, 0, 1652727000},
|
||||
{16, 1983520, 0, 1652813400},
|
||||
}
|
||||
|
||||
var stageNetHardForks = []HardFork{
|
||||
// version 1 from the start of the blockchain
|
||||
{1, 1, 0, 1341378000},
|
||||
|
||||
// versions 2-7 in rapid succession from March 13th, 2018
|
||||
{2, 32000, 0, 1521000000},
|
||||
{3, 33000, 0, 1521120000},
|
||||
{4, 34000, 0, 1521240000},
|
||||
{5, 35000, 0, 1521360000},
|
||||
{6, 36000, 0, 1521480000},
|
||||
{7, 37000, 0, 1521600000},
|
||||
{8, 176456, 0, 1537821770},
|
||||
{9, 177176, 0, 1537821771},
|
||||
{10, 269000, 0, 1550153694},
|
||||
{11, 269720, 0, 1550225678},
|
||||
{12, 454721, 0, 1571419280},
|
||||
{13, 675405, 0, 1598180817},
|
||||
{14, 676125, 0, 1598180818},
|
||||
{15, 1151000, 0, 1656629117},
|
||||
{16, 1151720, 0, 1656629118},
|
||||
}
|
||||
|
||||
var p2poolMainNetHardForks = []HardFork{
|
||||
// List of historical hardforks that p2pool networks went through
|
||||
// These are not kept in later p2pool releases.
|
||||
// If you ever find yourself back in time with a new p2pool release, it will start at its latest supported
|
||||
var p2poolMainNetHardForks = []monero.HardFork{
|
||||
{uint8(ShareVersion_V1), 0, 0, 0},
|
||||
// p2pool hardforks at 2023-03-18 21:00 UTC
|
||||
{uint8(ShareVersion_V2), 0, 0, 1679173200},
|
||||
}
|
||||
|
||||
var p2poolTestNetHardForks = []HardFork{
|
||||
var p2poolTestNetHardForks = []monero.HardFork{
|
||||
{uint8(ShareVersion_V1), 0, 0, 0},
|
||||
// p2pool hardforks at 2023-01-23 21:00 UTC
|
||||
{uint8(ShareVersion_V2), 0, 0, 1674507600},
|
||||
|
@ -112,41 +22,39 @@ var p2poolTestNetHardForks = []HardFork{
|
|||
//{uint8(ShareVersion_V2), 0, 0, 1678219200},
|
||||
}
|
||||
|
||||
var p2poolStageNetHardForks = []HardFork{
|
||||
var p2poolStageNetHardForks = []monero.HardFork{
|
||||
//always latest version
|
||||
{p2poolMainNetHardForks[len(p2poolMainNetHardForks)-1].Version, 0, 0, 0},
|
||||
}
|
||||
|
||||
func NetworkHardFork(consensus *Consensus) []HardFork {
|
||||
switch consensus.NetworkType {
|
||||
case NetworkMainnet:
|
||||
return mainNetHardForks
|
||||
case NetworkTestnet:
|
||||
return testNetHardForks
|
||||
case NetworkStagenet:
|
||||
return stageNetHardForks
|
||||
type ShareVersion uint8
|
||||
|
||||
func (v ShareVersion) String() string {
|
||||
switch v {
|
||||
case ShareVersion_None:
|
||||
return "none"
|
||||
default:
|
||||
panic("invalid network type for determining share version")
|
||||
return fmt.Sprintf("v%d", v)
|
||||
}
|
||||
}
|
||||
|
||||
func NetworkMajorVersion(consensus *Consensus, height uint64) uint8 {
|
||||
hardForks := NetworkHardFork(consensus)
|
||||
const (
|
||||
ShareVersion_None = ShareVersion(iota)
|
||||
|
||||
if len(hardForks) == 0 {
|
||||
return 0
|
||||
}
|
||||
// ShareVersion_V1 Initial version. Had optional deterministic private keys, and signaling of support of V2 on extra nonce
|
||||
ShareVersion_V1
|
||||
|
||||
result := hardForks[0].Version
|
||||
// ShareVersion_V2 Enforced deterministic private keys (and made more efficient)
|
||||
// Removed the private key field as it's implied, replaced with private key seed
|
||||
// Added extra fields to side data with extra nonces and random data, and carries software id and version
|
||||
// PPLNS Window weight is now dynamic up to minimum of mainchain difficulty * 2
|
||||
// Coinbase outputs are shuffled with a deterministic random method to mask output order on Monero
|
||||
ShareVersion_V2
|
||||
|
||||
for _, f := range hardForks[1:] {
|
||||
if height < f.Height {
|
||||
break
|
||||
}
|
||||
result = f.Version
|
||||
}
|
||||
return result
|
||||
}
|
||||
// ShareVersion_V3 Tentative future version with merge mining support.
|
||||
// Fixed Merge Mining Tag with a proper merkle root + proof on side data
|
||||
ShareVersion_V3
|
||||
)
|
||||
|
||||
// P2PoolShareVersion
|
||||
// P2Pool forks to v2 at 2023-03-18 21:00 UTC
|
||||
|
|
|
@ -37,25 +37,6 @@ const (
|
|||
// PoolBlockMaxTemplateSize Max P2P message size (128 KB) minus BLOCK_RESPONSE header (5 bytes)
|
||||
const PoolBlockMaxTemplateSize = 128*1024 - (1 + 4)
|
||||
|
||||
type ShareVersion uint8
|
||||
|
||||
func (v ShareVersion) String() string {
|
||||
switch v {
|
||||
case ShareVersion_None:
|
||||
return "none"
|
||||
default:
|
||||
return fmt.Sprintf("v%d", v)
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
ShareVersion_None ShareVersion = 0
|
||||
ShareVersion_V1 ShareVersion = 1
|
||||
ShareVersion_V2 ShareVersion = 2
|
||||
// ShareVersion_V3 Tentative future version with merge mining support
|
||||
ShareVersion_V3 ShareVersion = 3
|
||||
)
|
||||
|
||||
type UniquePoolBlockSlice []*PoolBlock
|
||||
|
||||
func (s UniquePoolBlockSlice) Get(consensus *Consensus, id types.Hash) *PoolBlock {
|
||||
|
@ -421,7 +402,7 @@ func (b *PoolBlock) FromCompactReader(consensus *Consensus, derivationCache Deri
|
|||
}
|
||||
|
||||
func (b *PoolBlock) consensusDecode(consensus *Consensus, derivationCache DerivationCacheInterface, reader utils.ReaderAndByteReader) (err error) {
|
||||
if expectedMajorVersion := NetworkMajorVersion(consensus, b.Main.Coinbase.GenHeight); expectedMajorVersion != b.Main.MajorVersion {
|
||||
if expectedMajorVersion := monero.NetworkMajorVersion(consensus.NetworkType.MustAddressNetwork(), b.Main.Coinbase.GenHeight); expectedMajorVersion != b.Main.MajorVersion {
|
||||
return fmt.Errorf("expected major version %d at height %d, got %d", expectedMajorVersion, b.Main.Coinbase.GenHeight, b.Main.MajorVersion)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue