From ef9e6f173bc2b2ec4cd4642c2513fc02176e9eac Mon Sep 17 00:00:00 2001 From: WeebDataHoarder <57538841+WeebDataHoarder@users.noreply.github.com> Date: Wed, 10 Apr 2024 03:53:12 +0200 Subject: [PATCH] Allow to change handshake consensus id under p2p server as temporary measure for testing --- p2pool/p2p/client.go | 6 +++--- p2pool/p2p/server.go | 33 ++++++++++++++++++++++++++------- p2pool/sidechain/consensus.go | 1 + 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/p2pool/p2p/client.go b/p2pool/p2p/client.go index 035dbbd..f3c9bb3 100644 --- a/p2pool/p2p/client.go +++ b/p2pool/p2p/client.go @@ -405,7 +405,7 @@ func (c *Client) OnConnection() { if c.IsIncomingConnection { //TODO: consensus MergeMiningId - if hash, ok := CalculateChallengeHash(c.handshakeChallenge, c.Owner.Consensus().Id, solution); !ok { + if hash, ok := CalculateChallengeHash(c.handshakeChallenge, c.Owner.HandshakeConsensusId(), solution); !ok { //not enough PoW c.Ban(DefaultBanTime, fmt.Errorf("not enough PoW on HANDSHAKE_SOLUTION, challenge = %s, solution = %d, calculated hash = %s, expected hash = %s", fasthex.EncodeToString(c.handshakeChallenge[:]), solution, hash.String(), challengeHash.String())) return @@ -416,7 +416,7 @@ func (c *Client) OnConnection() { } } else { //TODO: consensus MergeMiningId - if hash, _ := CalculateChallengeHash(c.handshakeChallenge, c.Owner.Consensus().Id, solution); hash != challengeHash { + if hash, _ := CalculateChallengeHash(c.handshakeChallenge, c.Owner.HandshakeConsensusId(), solution); hash != challengeHash { //wrong hash c.Ban(DefaultBanTime, fmt.Errorf("wrong hash HANDSHAKE_SOLUTION, challenge = %s, solution = %d, calculated hash = %s, expected hash = %s", fasthex.EncodeToString(c.handshakeChallenge[:]), solution, hash.String(), challengeHash.String())) return @@ -888,7 +888,7 @@ func (c *Client) sendHandshakeSolution(challenge HandshakeChallenge) { } //TODO: consensus MergeMiningId - if solution, hash, ok := FindChallengeSolution(challenge, c.Owner.Consensus().Id, stop); ok || c.IsIncomingConnection { + if solution, hash, ok := FindChallengeSolution(challenge, c.Owner.HandshakeConsensusId(), stop); ok || c.IsIncomingConnection { var buf [HandshakeChallengeSize + types.HashSize]byte copy(buf[:], hash[:]) diff --git a/p2pool/p2p/server.go b/p2pool/p2p/server.go index 74c2cd9..f3b1358 100644 --- a/p2pool/p2p/server.go +++ b/p2pool/p2p/server.go @@ -67,6 +67,8 @@ type BanEntry struct { type Server struct { p2pool P2PoolInterface + tempUseMergeMiningIdAsHandshake bool + peerId uint64 versionInformation p2pooltypes.PeerVersionInformation @@ -120,14 +122,23 @@ func NewServer(p2pool P2PoolInterface, listenAddress string, externalListenPort return nil, err } + //TODO: remove this when p2pool has proper hardfork method + var tempUseMergeMiningIdAsHandshake bool + if useMergeMining := ctx.Value("use_merge_mining_id"); useMergeMining != nil { + if v, ok := useMergeMining.(bool); ok { + tempUseMergeMiningIdAsHandshake = v + } + } + s := &Server{ - p2pool: p2pool, - listenAddress: addrPort, - externalListenPort: externalListenPort, - peerId: binary.LittleEndian.Uint64(peerId), - MaxOutgoingPeers: min(maxOutgoingPeers, 450), - MaxIncomingPeers: min(maxIncomingPeers, 450), - cachedBlocks: make(map[types.Hash]*sidechain.PoolBlock, p2pool.Consensus().ChainWindowSize*3), + p2pool: p2pool, + tempUseMergeMiningIdAsHandshake: tempUseMergeMiningIdAsHandshake, + listenAddress: addrPort, + externalListenPort: externalListenPort, + peerId: binary.LittleEndian.Uint64(peerId), + MaxOutgoingPeers: min(maxOutgoingPeers, 450), + MaxIncomingPeers: min(maxIncomingPeers, 450), + cachedBlocks: make(map[types.Hash]*sidechain.PoolBlock, p2pool.Consensus().ChainWindowSize*3), versionInformation: p2pooltypes.PeerVersionInformation{ SoftwareId: p2pooltypes.CurrentSoftwareId, SoftwareVersion: p2pooltypes.CurrentSoftwareVersion, @@ -895,6 +906,14 @@ func (s *Server) Broadcast(block *sidechain.PoolBlock) { }() } +func (s *Server) HandshakeConsensusId() types.Hash { + if s.tempUseMergeMiningIdAsHandshake { + return s.p2pool.Consensus().MergeMiningId + } else { + return s.p2pool.Consensus().Id + } +} + func (s *Server) Consensus() *sidechain.Consensus { return s.p2pool.Consensus() } diff --git a/p2pool/sidechain/consensus.go b/p2pool/sidechain/consensus.go index 2d084da..fc035cc 100644 --- a/p2pool/sidechain/consensus.go +++ b/p2pool/sidechain/consensus.go @@ -94,6 +94,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"` hasher randomx.Hasher