Add extra consensus id for temporary testing
This commit is contained in:
parent
decd52c0ca
commit
3e689ae7be
|
@ -54,7 +54,7 @@ func (p *P2PoolApi) WaitSync() (err error) {
|
||||||
time.Sleep(time.Second * 5)
|
time.Sleep(time.Second * 5)
|
||||||
}
|
}
|
||||||
utils.Logf("API", "SYNCHRONIZED (height %d, id %s, blocks %d)", status.Height, status.Id, status.Blocks)
|
utils.Logf("API", "SYNCHRONIZED (height %d, id %s, blocks %d)", status.Height, status.Id, status.Blocks)
|
||||||
utils.Logf("API", "Consensus id = %s / %s\n", p.Consensus().Id, p.Consensus().MergeMiningId)
|
utils.Logf("API", "Consensus id = %s\n", p.Consensus().Id)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ func (p *P2PoolApi) WaitSyncStart() (err error) {
|
||||||
if status.Synchronized {
|
if status.Synchronized {
|
||||||
utils.Logf("API", "SYNCHRONIZED (height %d, id %s, blocks %d)", status.Height, status.Id, status.Blocks)
|
utils.Logf("API", "SYNCHRONIZED (height %d, id %s, blocks %d)", status.Height, status.Id, status.Blocks)
|
||||||
}
|
}
|
||||||
utils.Logf("API", "Consensus id = %s / %s\n", p.Consensus().Id, p.Consensus().MergeMiningId)
|
utils.Logf("API", "Consensus id = %s\n", p.Consensus().Id)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,8 +67,6 @@ type BanEntry struct {
|
||||||
type Server struct {
|
type Server struct {
|
||||||
p2pool P2PoolInterface
|
p2pool P2PoolInterface
|
||||||
|
|
||||||
tempUseMergeMiningIdAsHandshake bool
|
|
||||||
|
|
||||||
peerId uint64
|
peerId uint64
|
||||||
versionInformation p2pooltypes.PeerVersionInformation
|
versionInformation p2pooltypes.PeerVersionInformation
|
||||||
|
|
||||||
|
@ -122,23 +120,14 @@ func NewServer(p2pool P2PoolInterface, listenAddress string, externalListenPort
|
||||||
return nil, err
|
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{
|
s := &Server{
|
||||||
p2pool: p2pool,
|
p2pool: p2pool,
|
||||||
tempUseMergeMiningIdAsHandshake: tempUseMergeMiningIdAsHandshake,
|
listenAddress: addrPort,
|
||||||
listenAddress: addrPort,
|
externalListenPort: externalListenPort,
|
||||||
externalListenPort: externalListenPort,
|
peerId: binary.LittleEndian.Uint64(peerId),
|
||||||
peerId: binary.LittleEndian.Uint64(peerId),
|
MaxOutgoingPeers: min(maxOutgoingPeers, 450),
|
||||||
MaxOutgoingPeers: min(maxOutgoingPeers, 450),
|
MaxIncomingPeers: min(maxIncomingPeers, 450),
|
||||||
MaxIncomingPeers: min(maxIncomingPeers, 450),
|
cachedBlocks: make(map[types.Hash]*sidechain.PoolBlock, p2pool.Consensus().ChainWindowSize*3),
|
||||||
cachedBlocks: make(map[types.Hash]*sidechain.PoolBlock, p2pool.Consensus().ChainWindowSize*3),
|
|
||||||
versionInformation: p2pooltypes.PeerVersionInformation{
|
versionInformation: p2pooltypes.PeerVersionInformation{
|
||||||
SoftwareId: p2pooltypes.CurrentSoftwareId,
|
SoftwareId: p2pooltypes.CurrentSoftwareId,
|
||||||
SoftwareVersion: p2pooltypes.CurrentSoftwareVersion,
|
SoftwareVersion: p2pooltypes.CurrentSoftwareVersion,
|
||||||
|
@ -907,11 +896,7 @@ func (s *Server) Broadcast(block *sidechain.PoolBlock) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) HandshakeConsensusId() types.Hash {
|
func (s *Server) HandshakeConsensusId() types.Hash {
|
||||||
if s.tempUseMergeMiningIdAsHandshake {
|
return s.p2pool.Consensus().Id
|
||||||
return s.p2pool.Consensus().MergeMiningId
|
|
||||||
} else {
|
|
||||||
return s.p2pool.Consensus().Id
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Consensus() *sidechain.Consensus {
|
func (s *Server) Consensus() *sidechain.Consensus {
|
||||||
|
|
|
@ -92,6 +92,9 @@ type Consensus struct {
|
||||||
ChainWindowSize uint64 `json:"pplns_window"`
|
ChainWindowSize uint64 `json:"pplns_window"`
|
||||||
UnclePenalty uint64 `json:"uncle_penalty"`
|
UnclePenalty uint64 `json:"uncle_penalty"`
|
||||||
|
|
||||||
|
// Extra additional string to add for testing usually
|
||||||
|
Extra string `json:"extra,omitempty"`
|
||||||
|
|
||||||
// HardFork optional hardfork information for p2pool
|
// HardFork optional hardfork information for p2pool
|
||||||
// If empty it will be filled with the default hardfork list to the corresponding NetworkType
|
// If empty it will be filled with the default hardfork list to the corresponding NetworkType
|
||||||
// Note: this is not supported by p2pool itself
|
// Note: this is not supported by p2pool itself
|
||||||
|
@ -100,14 +103,12 @@ type Consensus struct {
|
||||||
hasher randomx.Hasher
|
hasher randomx.Hasher
|
||||||
|
|
||||||
Id types.Hash `json:"id"`
|
Id types.Hash `json:"id"`
|
||||||
|
|
||||||
MergeMiningId types.Hash `json:"mm_id"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const SmallestMinimumDifficulty = 1000
|
const SmallestMinimumDifficulty = 1000
|
||||||
const LargestMinimumDifficulty = 1000000000
|
const LargestMinimumDifficulty = 1000000000
|
||||||
|
|
||||||
func NewConsensus(networkType NetworkType, poolName, poolPassword string, targetBlockTime, minimumDifficulty, chainWindowSize, unclePenalty uint64) *Consensus {
|
func NewConsensus(networkType NetworkType, poolName, poolPassword, extra string, targetBlockTime, minimumDifficulty, chainWindowSize, unclePenalty uint64) *Consensus {
|
||||||
c := &Consensus{
|
c := &Consensus{
|
||||||
NetworkType: networkType,
|
NetworkType: networkType,
|
||||||
PoolName: poolName,
|
PoolName: poolName,
|
||||||
|
@ -116,6 +117,7 @@ func NewConsensus(networkType NetworkType, poolName, poolPassword string, target
|
||||||
MinimumDifficulty: minimumDifficulty,
|
MinimumDifficulty: minimumDifficulty,
|
||||||
ChainWindowSize: chainWindowSize,
|
ChainWindowSize: chainWindowSize,
|
||||||
UnclePenalty: unclePenalty,
|
UnclePenalty: unclePenalty,
|
||||||
|
Extra: extra,
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.verify() {
|
if !c.verify() {
|
||||||
|
@ -169,14 +171,10 @@ func (c *Consensus) verify() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
var emptyHash types.Hash
|
var emptyHash types.Hash
|
||||||
c.Id = c.CalculateId(false)
|
c.Id = c.CalculateId()
|
||||||
if c.Id == emptyHash {
|
if c.Id == emptyHash {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
c.MergeMiningId = c.CalculateId(true)
|
|
||||||
if c.MergeMiningId == emptyHash {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(c.HardForks) == 0 {
|
if len(c.HardForks) == 0 {
|
||||||
switch c.NetworkType {
|
switch c.NetworkType {
|
||||||
|
@ -206,28 +204,20 @@ func (c *Consensus) CalculateSideTemplateIdPreAllocated(share *PoolBlock, buf []
|
||||||
_, _ = h.Write(buf)
|
_, _ = h.Write(buf)
|
||||||
buf, _ = share.Side.AppendBinary(buf[:0], share.ShareVersion())
|
buf, _ = share.Side.AppendBinary(buf[:0], share.ShareVersion())
|
||||||
_, _ = h.Write(buf)
|
_, _ = h.Write(buf)
|
||||||
|
_, _ = h.Write(c.Id[:])
|
||||||
if share.ShareVersion() > ShareVersion_V2 {
|
|
||||||
_, _ = h.Write(c.MergeMiningId[:])
|
|
||||||
} else {
|
|
||||||
_, _ = h.Write(c.Id[:])
|
|
||||||
}
|
|
||||||
crypto.HashFastSum(h, result[:])
|
crypto.HashFastSum(h, result[:])
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Consensus) CalculateSideChainIdFromBlobs(mainBlob, sideBlob []byte, isMergeMining bool) (result types.Hash) {
|
func (c *Consensus) CalculateSideChainIdFromBlobs(mainBlob, sideBlob []byte) (result types.Hash) {
|
||||||
h := crypto.GetKeccak256Hasher()
|
h := crypto.GetKeccak256Hasher()
|
||||||
defer crypto.PutKeccak256Hasher(h)
|
defer crypto.PutKeccak256Hasher(h)
|
||||||
|
|
||||||
_, _ = h.Write(mainBlob)
|
_, _ = h.Write(mainBlob)
|
||||||
_, _ = h.Write(sideBlob)
|
_, _ = h.Write(sideBlob)
|
||||||
|
|
||||||
if isMergeMining {
|
_, _ = h.Write(c.Id[:])
|
||||||
_, _ = h.Write(c.MergeMiningId[:])
|
|
||||||
} else {
|
|
||||||
_, _ = h.Write(c.Id[:])
|
|
||||||
}
|
|
||||||
crypto.HashFastSum(h, result[:])
|
crypto.HashFastSum(h, result[:])
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
@ -282,10 +272,11 @@ func (c *Consensus) GetHasher() randomx.Hasher {
|
||||||
return c.hasher
|
return c.hasher
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Consensus) CalculateId(mergeMining bool) types.Hash {
|
func (c *Consensus) CalculateId() types.Hash {
|
||||||
var buf []byte
|
var buf []byte
|
||||||
if mergeMining {
|
if c.Extra != "" {
|
||||||
buf = append(buf, 'm', 'm', 0)
|
buf = append(buf, c.Extra...)
|
||||||
|
buf = append(buf, 0)
|
||||||
}
|
}
|
||||||
buf = append(buf, c.NetworkType.String()...)
|
buf = append(buf, c.NetworkType.String()...)
|
||||||
buf = append(buf, 0)
|
buf = append(buf, 0)
|
||||||
|
@ -321,7 +312,6 @@ var ConsensusDefault = &Consensus{
|
||||||
UnclePenalty: 20,
|
UnclePenalty: 20,
|
||||||
HardForks: p2poolMainNetHardForks,
|
HardForks: p2poolMainNetHardForks,
|
||||||
Id: types.Hash{34, 175, 126, 231, 181, 11, 104, 146, 227, 153, 218, 107, 44, 108, 68, 39, 178, 81, 4, 212, 169, 4, 142, 0, 177, 110, 157, 240, 68, 7, 249, 24},
|
Id: types.Hash{34, 175, 126, 231, 181, 11, 104, 146, 227, 153, 218, 107, 44, 108, 68, 39, 178, 81, 4, 212, 169, 4, 142, 0, 177, 110, 157, 240, 68, 7, 249, 24},
|
||||||
MergeMiningId: types.Hash{107, 177, 178, 129, 71, 2, 66, 207, 56, 145, 102, 187, 105, 128, 102, 27, 68, 29, 81, 92, 114, 214, 215, 125, 158, 40, 117, 207, 32, 182, 142, 101},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var ConsensusMini = &Consensus{
|
var ConsensusMini = &Consensus{
|
||||||
|
@ -333,5 +323,4 @@ var ConsensusMini = &Consensus{
|
||||||
UnclePenalty: 20,
|
UnclePenalty: 20,
|
||||||
HardForks: p2poolMainNetHardForks,
|
HardForks: p2poolMainNetHardForks,
|
||||||
Id: types.Hash{57, 130, 201, 26, 149, 174, 199, 250, 66, 80, 189, 18, 108, 216, 194, 220, 136, 23, 63, 24, 64, 113, 221, 44, 219, 86, 39, 163, 53, 24, 126, 196},
|
Id: types.Hash{57, 130, 201, 26, 149, 174, 199, 250, 66, 80, 189, 18, 108, 216, 194, 220, 136, 23, 63, 24, 64, 113, 221, 44, 219, 86, 39, 163, 53, 24, 126, 196},
|
||||||
MergeMiningId: types.Hash{215, 23, 207, 132, 167, 193, 162, 243, 66, 3, 228, 99, 238, 140, 39, 46, 112, 158, 200, 37, 62, 100, 138, 59, 183, 233, 136, 91, 198, 34, 19, 39},
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,31 +6,22 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDefaultConsensusId(t *testing.T) {
|
func TestDefaultConsensusId(t *testing.T) {
|
||||||
id := ConsensusMini.CalculateId(false)
|
id := ConsensusMini.CalculateId()
|
||||||
if id != ConsensusMini.Id {
|
if id != ConsensusMini.Id {
|
||||||
t.Fatalf("wrong mini sidechain id, expected %s, got %s", ConsensusMini.Id.String(), id.String())
|
t.Fatalf("wrong mini sidechain id, expected %s, got %s", ConsensusMini.Id.String(), id.String())
|
||||||
}
|
}
|
||||||
id = ConsensusMini.CalculateId(true)
|
|
||||||
if id != ConsensusMini.MergeMiningId {
|
|
||||||
t.Fatalf("wrong mini merge mining sidechain id, expected %s, got %s", ConsensusMini.MergeMiningId.String(), id.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
id = ConsensusDefault.CalculateId(false)
|
id = ConsensusDefault.CalculateId()
|
||||||
if id != ConsensusDefault.Id {
|
if id != ConsensusDefault.Id {
|
||||||
t.Fatalf("wrong default sidechain id, expected %s, got %s", ConsensusDefault.Id.String(), id.String())
|
t.Fatalf("wrong default sidechain id, expected %s, got %s", ConsensusDefault.Id.String(), id.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
id = ConsensusDefault.CalculateId(true)
|
|
||||||
if id != ConsensusDefault.MergeMiningId {
|
|
||||||
t.Fatalf("wrong default merge mining sidechain id, expected %s, got %s", ConsensusDefault.MergeMiningId.String(), id.String())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOverlyLongConsensus(t *testing.T) {
|
func TestOverlyLongConsensus(t *testing.T) {
|
||||||
|
|
||||||
c := NewConsensus(NetworkMainnet, strings.Repeat("A", 128), strings.Repeat("A", 128), 10, 100000, 2160, 20)
|
c := NewConsensus(NetworkMainnet, strings.Repeat("A", 128), strings.Repeat("A", 128), "", 10, 100000, 2160, 20)
|
||||||
|
|
||||||
c2 := NewConsensus(NetworkMainnet, strings.Repeat("A", 128), strings.Repeat("A", 128), 100, 1000000, 1000, 30)
|
c2 := NewConsensus(NetworkMainnet, strings.Repeat("A", 128), strings.Repeat("A", 128), "", 100, 1000000, 1000, 30)
|
||||||
|
|
||||||
if c.Id == c2.Id {
|
if c.Id == c2.Id {
|
||||||
t.Fatalf("consensus is different but ids are equal, %s, %s", c.Id.String(), c2.Id.String())
|
t.Fatalf("consensus is different but ids are equal, %s, %s", c.Id.String(), c2.Id.String())
|
||||||
|
|
|
@ -315,7 +315,7 @@ func (c *SideChain) PoolBlockExternalVerify(block *PoolBlock) (missingBlocks []t
|
||||||
|
|
||||||
//verify template id against merkle proof
|
//verify template id against merkle proof
|
||||||
mmTag := block.MergeMiningTag()
|
mmTag := block.MergeMiningTag()
|
||||||
auxiliarySlot := merge_mining.GetAuxiliarySlot(c.Consensus().MergeMiningId, mmTag.Nonce, mmTag.NumberAuxiliaryChains)
|
auxiliarySlot := merge_mining.GetAuxiliarySlot(c.Consensus().Id, mmTag.Nonce, mmTag.NumberAuxiliaryChains)
|
||||||
|
|
||||||
if !block.Side.MerkleProof.Verify(templateId, int(auxiliarySlot), int(mmTag.NumberAuxiliaryChains), mmTag.RootHash) {
|
if !block.Side.MerkleProof.Verify(templateId, int(auxiliarySlot), int(mmTag.NumberAuxiliaryChains), mmTag.RootHash) {
|
||||||
return nil, fmt.Errorf("could not verify template id %s merkle proof against merkle tree root hash %s (number of chains = %d, nonce = %d, auxiliary slot = %d)", templateId, mmTag.RootHash, mmTag.NumberAuxiliaryChains, mmTag.Nonce, auxiliarySlot), true
|
return nil, fmt.Errorf("could not verify template id %s merkle proof against merkle tree root hash %s (number of chains = %d, nonce = %d, auxiliary slot = %d)", templateId, mmTag.RootHash, mmTag.NumberAuxiliaryChains, mmTag.Nonce, auxiliarySlot), true
|
||||||
|
@ -631,8 +631,7 @@ func (c *SideChain) verifyBlock(block *PoolBlock) (verification error, invalid e
|
||||||
len(block.Side.Uncles) != 0 ||
|
len(block.Side.Uncles) != 0 ||
|
||||||
block.Side.Difficulty.Cmp64(c.Consensus().MinimumDifficulty) != 0 ||
|
block.Side.Difficulty.Cmp64(c.Consensus().MinimumDifficulty) != 0 ||
|
||||||
block.Side.CumulativeDifficulty.Cmp64(c.Consensus().MinimumDifficulty) != 0 ||
|
block.Side.CumulativeDifficulty.Cmp64(c.Consensus().MinimumDifficulty) != 0 ||
|
||||||
(block.ShareVersion() > ShareVersion_V1 && block.ShareVersion() < ShareVersion_V3 && block.Side.CoinbasePrivateKeySeed != c.Consensus().Id) ||
|
(block.ShareVersion() > ShareVersion_V1 && block.Side.CoinbasePrivateKeySeed != c.Consensus().Id) {
|
||||||
(block.ShareVersion() > ShareVersion_V2 && block.Side.CoinbasePrivateKeySeed != c.Consensus().MergeMiningId) {
|
|
||||||
return nil, errors.New("genesis block has invalid parameters")
|
return nil, errors.New("genesis block has invalid parameters")
|
||||||
}
|
}
|
||||||
//this does not verify coinbase outputs, but that's fine
|
//this does not verify coinbase outputs, but that's fine
|
||||||
|
|
|
@ -218,11 +218,7 @@ func (s *Server) fillNewTemplateData(currentDifficulty types.Difficulty) error {
|
||||||
s.newTemplateData.Uncles = s.sidechain.GetPossibleUncles(s.tip, s.newTemplateData.SideHeight)
|
s.newTemplateData.Uncles = s.sidechain.GetPossibleUncles(s.tip, s.newTemplateData.SideHeight)
|
||||||
} else {
|
} else {
|
||||||
s.newTemplateData.PreviousTemplateId = types.ZeroHash
|
s.newTemplateData.PreviousTemplateId = types.ZeroHash
|
||||||
if s.newTemplateData.ShareVersion > sidechain.ShareVersion_V2 {
|
s.newTemplateData.TransactionPrivateKeySeed = s.sidechain.Consensus().Id
|
||||||
s.newTemplateData.TransactionPrivateKeySeed = s.sidechain.Consensus().MergeMiningId
|
|
||||||
} else {
|
|
||||||
s.newTemplateData.TransactionPrivateKeySeed = s.sidechain.Consensus().Id
|
|
||||||
}
|
|
||||||
s.newTemplateData.Difficulty = types.DifficultyFrom64(s.sidechain.Consensus().MinimumDifficulty)
|
s.newTemplateData.Difficulty = types.DifficultyFrom64(s.sidechain.Consensus().MinimumDifficulty)
|
||||||
s.newTemplateData.CumulativeDifficulty = types.DifficultyFrom64(s.sidechain.Consensus().MinimumDifficulty)
|
s.newTemplateData.CumulativeDifficulty = types.DifficultyFrom64(s.sidechain.Consensus().MinimumDifficulty)
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,11 +106,8 @@ func (tpl *Template) TemplateId(hasher *sha3.HasherState, preAllocatedBuffer []b
|
||||||
buf := tpl.Blob(preAllocatedBuffer, 0, 0, sideRandomNumber, sideExtraNonce, types.ZeroHash)
|
buf := tpl.Blob(preAllocatedBuffer, 0, 0, sideRandomNumber, sideExtraNonce, types.ZeroHash)
|
||||||
|
|
||||||
_, _ = hasher.Write(buf)
|
_, _ = hasher.Write(buf)
|
||||||
if tpl.ShareVersion(consensus) > sidechain.ShareVersion_V2 {
|
_, _ = hasher.Write(consensus.Id[:])
|
||||||
_, _ = hasher.Write(consensus.MergeMiningId[:])
|
|
||||||
} else {
|
|
||||||
_, _ = hasher.Write(consensus.Id[:])
|
|
||||||
}
|
|
||||||
crypto.HashFastSum(hasher, (*result)[:])
|
crypto.HashFastSum(hasher, (*result)[:])
|
||||||
hasher.Reset()
|
hasher.Reset()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue