git.gammaspectra.live/P2Pool/consensus@v0.0.0-20240403173234-a039820b20c9/p2pool/sidechain/hardfork.go (about)

     1  package sidechain
     2  
     3  type HardFork struct {
     4  	Version   uint8  `json:"version"`
     5  	Height    uint64 `json:"height"`
     6  	Threshold uint8  `json:"threshold"`
     7  	Time      uint64 `json:"time"`
     8  }
     9  
    10  var mainNetHardForks = []HardFork{
    11  	// version 1 from the start of the blockchain
    12  	{1, 1, 0, 1341378000},
    13  
    14  	// 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.
    15  	{2, 1009827, 0, 1442763710},
    16  
    17  	// version 3 starts from block 1141317, which is on or around the 24th of September, 2016. Fork time finalised on 2016-03-21.
    18  	{3, 1141317, 0, 1458558528},
    19  
    20  	// version 4 starts from block 1220516, which is on or around the 5th of January, 2017. Fork time finalised on 2016-09-18.
    21  	{4, 1220516, 0, 1483574400},
    22  
    23  	// version 5 starts from block 1288616, which is on or around the 15th of April, 2017. Fork time finalised on 2017-03-14.
    24  	{5, 1288616, 0, 1489520158},
    25  
    26  	// version 6 starts from block 1400000, which is on or around the 16th of September, 2017. Fork time finalised on 2017-08-18.
    27  	{6, 1400000, 0, 1503046577},
    28  
    29  	// version 7 starts from block 1546000, which is on or around the 6th of April, 2018. Fork time finalised on 2018-03-17.
    30  	{7, 1546000, 0, 1521303150},
    31  
    32  	// version 8 starts from block 1685555, which is on or around the 18th of October, 2018. Fork time finalised on 2018-09-02.
    33  	{8, 1685555, 0, 1535889547},
    34  
    35  	// version 9 starts from block 1686275, which is on or around the 19th of October, 2018. Fork time finalised on 2018-09-02.
    36  	{9, 1686275, 0, 1535889548},
    37  
    38  	// version 10 starts from block 1788000, which is on or around the 9th of March, 2019. Fork time finalised on 2019-02-10.
    39  	{10, 1788000, 0, 1549792439},
    40  
    41  	// version 11 starts from block 1788720, which is on or around the 10th of March, 2019. Fork time finalised on 2019-02-15.
    42  	{11, 1788720, 0, 1550225678},
    43  
    44  	// version 12 starts from block 1978433, which is on or around the 30th of November, 2019. Fork time finalised on 2019-10-18.
    45  	{12, 1978433, 0, 1571419280},
    46  
    47  	{13, 2210000, 0, 1598180817},
    48  	{14, 2210720, 0, 1598180818},
    49  
    50  	{15, 2688888, 0, 1656629117},
    51  	{16, 2689608, 0, 1656629118},
    52  }
    53  
    54  var testNetHardForks = []HardFork{
    55  	// version 1 from the start of the blockchain
    56  	{1, 1, 0, 1341378000},
    57  
    58  	// 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.
    59  	{2, 624634, 0, 1445355000},
    60  
    61  	// versions 3-5 were passed in rapid succession from September 18th, 2016
    62  	{3, 800500, 0, 1472415034},
    63  	{4, 801219, 0, 1472415035},
    64  	{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
    65  
    66  	{6, 971400, 0, 1501709789},
    67  	{7, 1057027, 0, 1512211236},
    68  	{8, 1057058, 0, 1533211200},
    69  	{9, 1057778, 0, 1533297600},
    70  	{10, 1154318, 0, 1550153694},
    71  	{11, 1155038, 0, 1550225678},
    72  	{12, 1308737, 0, 1569582000},
    73  	{13, 1543939, 0, 1599069376},
    74  	{14, 1544659, 0, 1599069377},
    75  	{15, 1982800, 0, 1652727000},
    76  	{16, 1983520, 0, 1652813400},
    77  }
    78  
    79  var stageNetHardForks = []HardFork{
    80  	// version 1 from the start of the blockchain
    81  	{1, 1, 0, 1341378000},
    82  
    83  	// versions 2-7 in rapid succession from March 13th, 2018
    84  	{2, 32000, 0, 1521000000},
    85  	{3, 33000, 0, 1521120000},
    86  	{4, 34000, 0, 1521240000},
    87  	{5, 35000, 0, 1521360000},
    88  	{6, 36000, 0, 1521480000},
    89  	{7, 37000, 0, 1521600000},
    90  	{8, 176456, 0, 1537821770},
    91  	{9, 177176, 0, 1537821771},
    92  	{10, 269000, 0, 1550153694},
    93  	{11, 269720, 0, 1550225678},
    94  	{12, 454721, 0, 1571419280},
    95  	{13, 675405, 0, 1598180817},
    96  	{14, 676125, 0, 1598180818},
    97  	{15, 1151000, 0, 1656629117},
    98  	{16, 1151720, 0, 1656629118},
    99  }
   100  
   101  var p2poolMainNetHardForks = []HardFork{
   102  	{uint8(ShareVersion_V1), 0, 0, 0},
   103  	// p2pool hardforks at 2023-03-18 21:00 UTC
   104  	{uint8(ShareVersion_V2), 0, 0, 1679173200},
   105  }
   106  
   107  var p2poolTestNetHardForks = []HardFork{
   108  	{uint8(ShareVersion_V1), 0, 0, 0},
   109  	// p2pool hardforks at 2023-01-23 21:00 UTC
   110  	{uint8(ShareVersion_V2), 0, 0, 1674507600},
   111  	//alternate hardfork at 2023-03-07 20:00 UTC 1678219200
   112  	//{uint8(ShareVersion_V2), 0, 0, 1678219200},
   113  }
   114  
   115  var p2poolStageNetHardForks = []HardFork{
   116  	//always latest version
   117  	{p2poolMainNetHardForks[len(p2poolMainNetHardForks)-1].Version, 0, 0, 0},
   118  }
   119  
   120  func NetworkHardFork(consensus *Consensus) []HardFork {
   121  	switch consensus.NetworkType {
   122  	case NetworkMainnet:
   123  		return mainNetHardForks
   124  	case NetworkTestnet:
   125  		return testNetHardForks
   126  	case NetworkStagenet:
   127  		return stageNetHardForks
   128  	default:
   129  		panic("invalid network type for determining share version")
   130  	}
   131  }
   132  
   133  func NetworkMajorVersion(consensus *Consensus, height uint64) uint8 {
   134  	hardForks := NetworkHardFork(consensus)
   135  
   136  	if len(hardForks) == 0 {
   137  		return 0
   138  	}
   139  
   140  	result := hardForks[0].Version
   141  
   142  	for _, f := range hardForks[1:] {
   143  		if height < f.Height {
   144  			break
   145  		}
   146  		result = f.Version
   147  	}
   148  	return result
   149  }
   150  
   151  func P2PoolShareVersion(consensus *Consensus, timestamp uint64) ShareVersion {
   152  	hardForks := consensus.HardForks
   153  
   154  	if len(hardForks) == 0 {
   155  		return ShareVersion_None
   156  	}
   157  
   158  	result := hardForks[0].Version
   159  
   160  	for _, f := range hardForks[1:] {
   161  		if timestamp < f.Time {
   162  			break
   163  		}
   164  		result = f.Version
   165  	}
   166  	return ShareVersion(result)
   167  }