Allow to change handshake consensus id under p2p server as temporary measure for testing
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
DataHoarder 2024-04-10 03:53:12 +02:00
parent 6efd52cae7
commit ef9e6f173b
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk
3 changed files with 30 additions and 10 deletions

View file

@ -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[:])

View file

@ -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()
}

View file

@ -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