Skip to content

Commit

Permalink
Add cancun block height parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
timemarkovqtum committed Sep 5, 2024
1 parent c51d2ee commit bbc621e
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 10 deletions.
11 changes: 11 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ std::string CChainParams::EVMGenesisInfo() const
evmConsensus.nMuirGlacierHeight = consensus.nMuirGlacierHeight;
evmConsensus.nLondonHeight = consensus.nLondonHeight;
evmConsensus.nShanghaiHeight = consensus.nShanghaiHeight;
evmConsensus.nCancunHeight = consensus.nCancunHeight;
return dev::eth::genesisInfoQtum(GetEVMNetwork(), evmConsensus);
}

Expand Down Expand Up @@ -338,3 +339,13 @@ void UpdateShanghaiHeight(int nHeight)
{
const_cast<CChainParams*>(globalChainParams.get())->UpdateShanghaiHeight(nHeight);
}

void CChainParams::UpdateCancunHeight(int nHeight)
{
consensus.nCancunHeight = nHeight;
}

void UpdateCancunHeight(int nHeight)
{
const_cast<CChainParams*>(globalChainParams.get())->UpdateCancunHeight(nHeight);
}
5 changes: 5 additions & 0 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,9 @@ void UpdateTaprootHeight(int nHeight);
*/
void UpdateShanghaiHeight(int nHeight);

/**
* Allows modifying the cancun block height regtest parameter.
*/
void UpdateCancunHeight(int nHeight);

#endif // BITCOIN_CHAINPARAMS_H
2 changes: 2 additions & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ struct Params {
int nLondonHeight;
/** Block height at which EVM Shanghai fork becomes active */
int nShanghaiHeight;
/** Block height at which EVM Cancun fork becomes active */
int nCancunHeight;
/**
* Minimum blocks including miner confirmation of the total of 2016 blocks in a retargeting period,
* (nPowTargetTimespan / nPowTargetSpacing) which is also used for BIP9 deployments.
Expand Down
1 change: 1 addition & 0 deletions src/eth_client/libethashseal/GenesisInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ std::string dev::eth::genesisInfoQtum(Network _n, EVMConsensus _consensus)
ReplaceInt(_consensus.nMuirGlacierHeight, "MUIR_STARTING_BLOCK", _genesisInfo);
ReplaceInt(_consensus.nLondonHeight, "LONDON_STARTING_BLOCK", _genesisInfo);
ReplaceInt(_consensus.nShanghaiHeight, "SHANGHAI_STARTING_BLOCK", _genesisInfo);
ReplaceInt(_consensus.nCancunHeight, "CANCUN_STARTING_BLOCK", _genesisInfo);
return _genesisInfo;
}
4 changes: 3 additions & 1 deletion src/eth_client/libethashseal/GenesisInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ struct EVMConsensus
QIP7Height(nHeight),
nMuirGlacierHeight(nHeight),
nLondonHeight(nHeight),
nShanghaiHeight(nHeight)
nShanghaiHeight(nHeight),
nCancunHeight(nHeight)
{}

int QIP6Height = 0x7fffffff;
int QIP7Height = 0x7fffffff;
int nMuirGlacierHeight = 0x7fffffff;
int nLondonHeight = 0x7fffffff;
int nShanghaiHeight = 0x7fffffff;
int nCancunHeight = 0x7fffffff;
};

/**
Expand Down
1 change: 1 addition & 0 deletions src/eth_client/libethashseal/genesis/qtumNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ R"E(
"berlinForkBlock": "LONDON_STARTING_BLOCK",
"londonForkBlock": "LONDON_STARTING_BLOCK",
"shanghaiForkBlock": "SHANGHAI_STARTING_BLOCK",
"cancunForkBlock": "CANCUN_STARTING_BLOCK",
"networkID" : "0x51",
"chainID": "0x51",
"maximumExtraDataSize": "0x20",
Expand Down
2 changes: 2 additions & 0 deletions src/eth_client/libethcore/ChainOperationParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ EVMSchedule const& ChainOperationParams::forkScheduleForBlockNumber(u256 const&
{
if (_blockNumber >= experimentalForkBlock)
return ExperimentalSchedule;
else if (_blockNumber >= cancunForkBlock)
return CancunSchedule;
else if (_blockNumber >= shanghaiForkBlock)
return ShanghaiSchedule;
else if (_blockNumber >= londonForkBlock)
Expand Down
1 change: 1 addition & 0 deletions src/eth_client/libethcore/ChainOperationParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ struct ChainOperationParams
u256 lastForkBlock = c_infiniteBlockNumber;
u256 qip6ForkBlock = c_infiniteBlockNumber;
u256 shanghaiForkBlock = c_infiniteBlockNumber;
u256 cancunForkBlock = c_infiniteBlockNumber;
AdditionalEIPs lastForkAdditionalEIPs;
int chainID = 0; // Distinguishes different chains (mainnet, Ropsten, etc).
int networkID = 0; // Distinguishes different sub protocols.
Expand Down
9 changes: 9 additions & 0 deletions src/eth_client/libethcore/EVMSchedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ struct EVMSchedule
bool eip2929Mode = false;
bool eip1559Mode = false;
bool eip6049Mode = false;
bool eip1153Mode = false;
bool haveBitwiseShifting = false;
bool haveRevert = false;
bool haveReturnData = false;
Expand Down Expand Up @@ -206,6 +207,14 @@ static const EVMSchedule ShanghaiSchedule = [] {
return schedule;
}();

static const EVMSchedule CancunSchedule = [] {
EVMSchedule schedule = ShanghaiSchedule;
// Cancun revision
schedule.eip1153Mode = true;

return schedule;
}();

static const EVMSchedule ExperimentalSchedule = [] {
EVMSchedule schedule = ShanghaiSchedule;
schedule.accountVersion = 1;
Expand Down
1 change: 1 addition & 0 deletions src/eth_client/libethereum/ChainParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ void ChainParams::loadConfig(
setOptionalU256Parameter(experimentalForkBlock, c_experimentalForkBlock);
setOptionalU256Parameter(qip6ForkBlock, c_qip6ForkBlock);
setOptionalU256Parameter(shanghaiForkBlock, c_shanghaiForkBlock);
setOptionalU256Parameter(cancunForkBlock, c_cancunForkBlock);

lastForkBlock = findMaxForkBlockNumber(params);
lastForkWithAdditionalEIPsSchedule = forkScheduleForBlockNumber(lastForkBlock);
Expand Down
1 change: 1 addition & 0 deletions src/eth_client/libethereum/ValidationSchemes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ string const c_networkID = "networkID";
string const c_allowFutureBlocks = "allowFutureBlocks";
string const c_qip6ForkBlock = "qip6ForkBlock";
string const c_shanghaiForkBlock = "shanghaiForkBlock";
string const c_cancunForkBlock = "cancunForkBlock";

void validateConfigJson(js::mObject const& _obj)
{
Expand Down
1 change: 1 addition & 0 deletions src/eth_client/libethereum/ValidationSchemes.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ extern std::string const c_networkID;
extern std::string const c_allowFutureBlocks;
extern std::string const c_qip6ForkBlock;
extern std::string const c_shanghaiForkBlock;
extern std::string const c_cancunForkBlock;

// Validate config.json that contains chain params and genesis state
void validateConfigJson(json_spirit::mObject const& _obj);
Expand Down
2 changes: 2 additions & 0 deletions src/eth_client/libevm/EVMC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace
{
evmc_revision toRevision(EVMSchedule const& _schedule) noexcept
{
if (_schedule.eip1153Mode)
return EVMC_CANCUN;
if (_schedule.eip6049Mode)
return EVMC_SHANGHAI;
if (_schedule.eip1559Mode)
Expand Down
15 changes: 15 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ void SetupServerArgs(ArgsManager& argsman)
argsman.AddArg("-londonheight=<n>", "Use given block height to check contracts with EVM London (regtest-only)", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-taprootheight=<n>", "Use given block height to check taproot (regtest-only)", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-shanghaiheight=<n>", "Use given block height to check contracts with EVM Shanghai (regtest-only)", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-cancunheight=<n>", "Use given block height to check contracts with EVM Cancun (regtest-only)", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);

SetupChainParamsBaseOptions(argsman);

Expand Down Expand Up @@ -1337,6 +1338,20 @@ bool AppInitParameterInteraction(const ArgsManager& args)
}
}

if (args.IsArgSet("-cancunheight")) {
// Allow overriding EVM Cancun block height for testing
if (!chainparams.MineBlocksOnDemand()) {
return InitError(Untranslated("Short EVM Cancun height may only be overridden on regtest."));
}

int cancunheight = args.GetIntArg("-cancunheight", 0);
if(cancunheight >= 0)
{
UpdateCancunHeight(cancunheight);
LogPrintf("Activate EVM Cancun at block height %d\n.", cancunheight);
}
}

if(args.IsArgSet("-stakingallowlist") && args.IsArgSet("-stakingexcludelist"))
{
return InitError(Untranslated("Either -stakingallowlist or -stakingexcludelist parameter can be specified to the staker, not both."));
Expand Down
4 changes: 4 additions & 0 deletions src/kernel/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class CMainParams : public CChainParams {
consensus.nMuirGlacierHeight = 845000;
consensus.nLondonHeight = 2080512;
consensus.nShanghaiHeight = 3385122;
consensus.nCancunHeight = 0x7fffffff;
consensus.powLimit = uint256S("0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.posLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.QIP9PosLimit = uint256S("0000000000001fffffffffffffffffffffffffffffffffffffffffffffffffff"); // The new POS-limit activated after QIP9
Expand Down Expand Up @@ -260,6 +261,7 @@ class CTestNetParams : public CChainParams {
consensus.nMuirGlacierHeight = 806600;
consensus.nLondonHeight = 1967616;
consensus.nShanghaiHeight = 3298892;
consensus.nCancunHeight = 0x7fffffff;
consensus.powLimit = uint256S("0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.posLimit = uint256S("0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.QIP9PosLimit = uint256S("0000000000001fffffffffffffffffffffffffffffffffffffffffffffffffff"); // The new POS-limit activated after QIP9
Expand Down Expand Up @@ -436,6 +438,7 @@ class SigNetParams : public CChainParams {
consensus.nMuirGlacierHeight = 0;
consensus.nLondonHeight = 0;
consensus.nShanghaiHeight = 0;
consensus.nCancunHeight = 0;
consensus.powLimit = uint256S("0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.posLimit = uint256S("0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.QIP9PosLimit = uint256S("0000000000001fffffffffffffffffffffffffffffffffffffffffffffffffff"); // The new POS-limit activated after QIP9
Expand Down Expand Up @@ -544,6 +547,7 @@ class CRegTestParams : public CChainParams
consensus.nMuirGlacierHeight = 0;
consensus.nLondonHeight = 0;
consensus.nShanghaiHeight = 0;
consensus.nCancunHeight = 0;
consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.posLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.QIP9PosLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); // The new POS-limit activated after QIP9
Expand Down
1 change: 1 addition & 0 deletions src/kernel/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class CChainParams
void UpdateLondonHeight(int nHeight);
void UpdateTaprootHeight(int nHeight);
void UpdateShanghaiHeight(int nHeight);
void UpdateCancunHeight(int nHeight);

std::optional<AssumeutxoData> AssumeutxoForHeight(int height) const
{
Expand Down
8 changes: 4 additions & 4 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3678,9 +3678,9 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
return;
}

if (m_chainman.ActiveChain().Tip()->nHeight >= m_chainparams.GetConsensus().nShanghaiHeight && nVersion < MIN_PEER_PROTO_VERSION_AFTER_EVMSHANGHAI) {
if (m_chainman.ActiveChain().Tip()->nHeight >= m_chainparams.GetConsensus().nCancunHeight && nVersion < MIN_PEER_PROTO_VERSION_AFTER_EVMCANCUN) {
// disconnect from peers older than this proto version
LogPrint(BCLog::NET, "peer=%d using obsolete version after evm Shanghai hardfork %i; disconnecting\n", pfrom.GetId(), nVersion);
LogPrint(BCLog::NET, "peer=%d using obsolete version after evm Cancun hardfork %i; disconnecting\n", pfrom.GetId(), nVersion);
pfrom.fDisconnect = true;
return;
}
Expand Down Expand Up @@ -3876,9 +3876,9 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
return;
}

if (pfrom.nVersion < MIN_PEER_PROTO_VERSION_AFTER_EVMSHANGHAI && m_chainman.ActiveChain().Tip()->nHeight >= m_chainparams.GetConsensus().nShanghaiHeight) {
if (pfrom.nVersion < MIN_PEER_PROTO_VERSION_AFTER_EVMCANCUN && m_chainman.ActiveChain().Tip()->nHeight >= m_chainparams.GetConsensus().nCancunHeight) {
// disconnect from peers older than this proto version
LogPrint(BCLog::NET, "peer=%d using obsolete version after evm Shanghai hardfork %i; disconnecting\n", pfrom.GetId(), pfrom.nVersion);
LogPrint(BCLog::NET, "peer=%d using obsolete version after evm Cancun hardfork %i; disconnecting\n", pfrom.GetId(), pfrom.nVersion);
pfrom.fDisconnect = true;
return;
}
Expand Down
10 changes: 5 additions & 5 deletions src/node/protocol_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
* network protocol versioning
*/

static const int PROTOCOL_VERSION = 70021;
static const int PROTOCOL_VERSION = 70022;

//! initial proto version, to be increased after version/verack negotiation
static const int INIT_PROTO_VERSION = 209;

//! disconnect from peers older than this proto version
static const int MIN_PEER_PROTO_VERSION = 70020;
//! disconnect from peers older than this proto version (evm Shanghai)
static const int MIN_PEER_PROTO_VERSION = 70021;

//! disconnect from peers older than this proto version after evm Shanghai
static const int MIN_PEER_PROTO_VERSION_AFTER_EVMSHANGHAI = 70021;
//! disconnect from peers older than this proto version after evm Cancun
static const int MIN_PEER_PROTO_VERSION_AFTER_EVMCANCUN = 70022;

//! BIP 0031, pong message, is enabled for all versions AFTER this one
static const int BIP0031_VERSION = 60000;
Expand Down

0 comments on commit bbc621e

Please sign in to comment.