added in segwit hardfork (mimics lbrycrd)
also validated testnet
This commit is contained in:
parent
cb7175bd70
commit
d4073bd18d
10 changed files with 88 additions and 53 deletions
|
@ -230,8 +230,8 @@ func ValidateWitnessCommitment(blk *btcutil.Block) error {
|
|||
coinbaseWitness := coinbaseTx.MsgTx().TxIn[0].Witness
|
||||
if len(coinbaseWitness) != 1 {
|
||||
str := fmt.Sprintf("the coinbase transaction has %d items in "+
|
||||
"its witness stack when only one is allowed",
|
||||
len(coinbaseWitness))
|
||||
"its witness stack when only one is allowed. Height: %d",
|
||||
len(coinbaseWitness), blk.Height())
|
||||
return ruleError(ErrInvalidWitnessCommitment, str)
|
||||
}
|
||||
witnessNonce := coinbaseWitness[0]
|
||||
|
|
|
@ -302,6 +302,12 @@ func (b *BlockChain) deploymentState(prevNode *blockNode, deploymentID uint32) (
|
|||
}
|
||||
|
||||
deployment := &b.chainParams.Deployments[deploymentID]
|
||||
|
||||
// added to mimic LBRYcrd:
|
||||
if deployment.ForceActiveAt > 0 && prevNode != nil && prevNode.height+1 >= deployment.ForceActiveAt {
|
||||
return ThresholdActive, nil
|
||||
}
|
||||
|
||||
checker := deploymentChecker{deployment: deployment, chain: b}
|
||||
cache := &b.deploymentCaches[deploymentID]
|
||||
|
||||
|
|
|
@ -195,6 +195,12 @@ func (b *BlockChain) calcNextBlockVersion(prevNode *blockNode) (int32, error) {
|
|||
expectedVersion := uint32(vbTopBits)
|
||||
for id := 0; id < len(b.chainParams.Deployments); id++ {
|
||||
deployment := &b.chainParams.Deployments[id]
|
||||
|
||||
// added to mimic LBRYcrd:
|
||||
if deployment.ForceActiveAt > 0 && prevNode != nil && prevNode.height+1 >= deployment.ForceActiveAt {
|
||||
continue
|
||||
}
|
||||
|
||||
cache := &b.deploymentCaches[id]
|
||||
checker := deploymentChecker{deployment: deployment, chain: b}
|
||||
state, err := b.thresholdState(prevNode, checker, cache)
|
||||
|
|
|
@ -20,11 +20,11 @@ const (
|
|||
// weight of a "base" byte is 4, while the weight of a witness byte is
|
||||
// 1. As a result, for a block to be valid, the BlockWeight MUST be
|
||||
// less than, or equal to MaxBlockWeight.
|
||||
MaxBlockWeight = 4000000
|
||||
MaxBlockWeight = 8000000
|
||||
|
||||
// MaxBlockBaseSize is the maximum number of bytes within a block
|
||||
// which can be allocated to non-witness data.
|
||||
MaxBlockBaseSize = 2000000
|
||||
MaxBlockBaseSize = 8000000
|
||||
|
||||
// MaxBlockSigOpsCost is the maximum number of signature operations
|
||||
// allowed for a block. It is calculated via a weighted algorithm which
|
||||
|
|
|
@ -102,6 +102,9 @@ type ConsensusDeployment struct {
|
|||
// ExpireTime is the median block time after which the attempted
|
||||
// deployment expires.
|
||||
ExpireTime uint64
|
||||
|
||||
// ForceActiveAt is added by LBRY to bypass consensus. Features are activated via hard-fork instead.
|
||||
ForceActiveAt int32
|
||||
}
|
||||
|
||||
// Constants that define the deployment offset in the deployments field of the
|
||||
|
@ -321,14 +324,16 @@ var MainNetParams = Params{
|
|||
ExpireTime: 1230767999, // December 31, 2008 UTC
|
||||
},
|
||||
DeploymentCSV: {
|
||||
BitNumber: 0,
|
||||
StartTime: 1462060800, // May 1st, 2016
|
||||
ExpireTime: 1493596800, // May 1st, 2017
|
||||
BitNumber: 0,
|
||||
StartTime: 1462060800, // May 1st, 2016
|
||||
ExpireTime: 1493596800, // May 1st, 2017
|
||||
ForceActiveAt: 200000,
|
||||
},
|
||||
DeploymentSegwit: {
|
||||
BitNumber: 1,
|
||||
StartTime: 1547942400, // Jan 20, 2019
|
||||
ExpireTime: 1548288000, // Jan 24, 2019
|
||||
BitNumber: 1,
|
||||
StartTime: 1547942400, // Jan 20, 2019
|
||||
ExpireTime: 1548288000, // Jan 24, 2019
|
||||
ForceActiveAt: 680770,
|
||||
},
|
||||
},
|
||||
|
||||
|
@ -368,15 +373,15 @@ var RegressionNetParams = Params{
|
|||
PowLimit: regressionPowLimit,
|
||||
PowLimitBits: 0x207fffff,
|
||||
CoinbaseMaturity: 100,
|
||||
BIP0034Height: 100000000, // Not active - Permit ver 1 blocks
|
||||
BIP0065Height: 1351, // Used by regression tests
|
||||
BIP0066Height: 1251, // Used by regression tests
|
||||
BIP0034Height: 1000,
|
||||
BIP0065Height: 1351, // Used by regression tests
|
||||
BIP0066Height: 1251, // Used by regression tests
|
||||
SubsidyReductionInterval: 1 << 5,
|
||||
TargetTimespan: time.Second,
|
||||
TargetTimePerBlock: time.Second,
|
||||
RetargetAdjustmentFactor: 4, // 25% less, 400% more
|
||||
ReduceMinDifficulty: false,
|
||||
MinDiffReductionTime: time.Minute * 20, // TargetTimePerBlock * 2
|
||||
MinDiffReductionTime: 0,
|
||||
GenerateSupported: true,
|
||||
|
||||
// Checkpoints ordered from oldest to newest.
|
||||
|
@ -395,14 +400,16 @@ var RegressionNetParams = Params{
|
|||
ExpireTime: math.MaxInt64, // Never expires
|
||||
},
|
||||
DeploymentCSV: {
|
||||
BitNumber: 0,
|
||||
StartTime: 0, // Always available for vote
|
||||
ExpireTime: math.MaxInt64, // Never expires
|
||||
BitNumber: 0,
|
||||
StartTime: 0, // Always available for vote
|
||||
ExpireTime: math.MaxInt64, // Never expires
|
||||
ForceActiveAt: 1,
|
||||
},
|
||||
DeploymentSegwit: {
|
||||
BitNumber: 1,
|
||||
StartTime: 0,
|
||||
ExpireTime: math.MaxInt64, // Not in the roadmap
|
||||
BitNumber: 1,
|
||||
StartTime: 0,
|
||||
ExpireTime: math.MaxInt64,
|
||||
ForceActiveAt: 150,
|
||||
},
|
||||
},
|
||||
|
||||
|
@ -435,31 +442,29 @@ var TestNet3Params = Params{
|
|||
Net: wire.TestNet3,
|
||||
DefaultPort: "19246",
|
||||
DNSSeeds: []DNSSeed{
|
||||
{"testdnsseed1.lbry.io", true},
|
||||
{"testdnsseed2.lbry.io", true},
|
||||
{"testdnsseed1.lbry.com", true},
|
||||
{"testdnsseed2.lbry.com", true},
|
||||
},
|
||||
|
||||
// Chain parameters
|
||||
GenesisBlock: &testNet3GenesisBlock,
|
||||
GenesisHash: &testNet3GenesisHash,
|
||||
PowLimit: testNet3PowLimit,
|
||||
PowLimitBits: 0x1d00ffff,
|
||||
BIP0034Height: 21111, // 0000000023b3a96d3484e5abb3755c413e7d41500f8e2a5c3f0dd01299cd8ef8
|
||||
BIP0065Height: 581885, // 00000000007f6655f22f98e72ed80d8b06dc761d5da09df0fa1dc4be4f861eb6
|
||||
BIP0066Height: 330776, // 000000002104c8c45e99a8853285a3b592602a3ccde2b832481da85e9e4ba182
|
||||
PowLimitBits: 0x1f00ffff,
|
||||
BIP0034Height: 21111, // 0x0000000023b3a96d3484e5abb3755c413e7d41500f8e2a5c3f0dd01299cd8ef8
|
||||
BIP0065Height: 1200000,
|
||||
BIP0066Height: 1200000,
|
||||
CoinbaseMaturity: 100,
|
||||
SubsidyReductionInterval: 210000,
|
||||
TargetTimespan: time.Hour * 24 * 14, // 14 days
|
||||
TargetTimePerBlock: time.Minute * 10, // 10 minutes
|
||||
RetargetAdjustmentFactor: 4, // 25% less, 400% more
|
||||
ReduceMinDifficulty: true,
|
||||
MinDiffReductionTime: time.Minute * 20, // TargetTimePerBlock * 2
|
||||
GenerateSupported: false,
|
||||
SubsidyReductionInterval: 1 << 5,
|
||||
TargetTimespan: time.Second * 150, // retarget every block
|
||||
TargetTimePerBlock: time.Second * 150, // 150 seconds
|
||||
RetargetAdjustmentFactor: 4, // 25% less, 400% more
|
||||
ReduceMinDifficulty: false,
|
||||
MinDiffReductionTime: 0,
|
||||
GenerateSupported: true,
|
||||
|
||||
// Checkpoints ordered from oldest to newest.
|
||||
Checkpoints: []Checkpoint{
|
||||
{0, newHashFromStr("9c89283ba0f3227f6c03b70216b9f665f0118d5e0fa729cedf4fb34d6a34f463")},
|
||||
},
|
||||
Checkpoints: []Checkpoint{},
|
||||
|
||||
// Consensus rule change deployments.
|
||||
//
|
||||
|
@ -479,9 +484,10 @@ var TestNet3Params = Params{
|
|||
ExpireTime: 1493596800, // May 1st, 2017
|
||||
},
|
||||
DeploymentSegwit: {
|
||||
BitNumber: 1,
|
||||
StartTime: 1462060800,
|
||||
ExpireTime: 1493596800,
|
||||
BitNumber: 1,
|
||||
StartTime: 1462060800, // May 1st 2016
|
||||
ExpireTime: 1493596800, // May 1st 2017
|
||||
ForceActiveAt: 1198600,
|
||||
},
|
||||
},
|
||||
|
||||
|
@ -495,7 +501,7 @@ var TestNet3Params = Params{
|
|||
// Address encoding magics
|
||||
PubKeyHashAddrID: 111,
|
||||
ScriptHashAddrID: 196,
|
||||
PrivateKeyID: 0xef, // starts with 9 (uncompressed) or c (compressed)
|
||||
PrivateKeyID: 239,
|
||||
|
||||
// BIP32 hierarchical deterministic extended key magics
|
||||
HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94}, // starts with tprv
|
||||
|
@ -529,11 +535,11 @@ var SimNetParams = Params{
|
|||
BIP0066Height: 0, // Always active on simnet
|
||||
CoinbaseMaturity: 100,
|
||||
SubsidyReductionInterval: 210000,
|
||||
TargetTimespan: time.Hour * 24 * 14, // 14 days
|
||||
TargetTimePerBlock: time.Minute * 10, // 10 minutes
|
||||
RetargetAdjustmentFactor: 4, // 25% less, 400% more
|
||||
TargetTimespan: time.Second * 150,
|
||||
TargetTimePerBlock: time.Second * 150,
|
||||
RetargetAdjustmentFactor: 4, // 25% less, 400% more
|
||||
ReduceMinDifficulty: true,
|
||||
MinDiffReductionTime: time.Minute * 20, // TargetTimePerBlock * 2
|
||||
MinDiffReductionTime: 0,
|
||||
GenerateSupported: true,
|
||||
|
||||
// Checkpoints ordered from oldest to newest.
|
||||
|
@ -558,8 +564,8 @@ var SimNetParams = Params{
|
|||
},
|
||||
DeploymentSegwit: {
|
||||
BitNumber: 1,
|
||||
StartTime: math.MaxInt64, // Not in the roadmap
|
||||
ExpireTime: math.MaxInt64, // Not in the roadmap
|
||||
StartTime: 0,
|
||||
ExpireTime: math.MaxInt64,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
@ -124,7 +124,10 @@ func (rt *RamTrie) completeHash(h *chainhash.Hash, childKey KeyType) []byte {
|
|||
}
|
||||
|
||||
func (rt *RamTrie) MerkleHashAllClaims() *chainhash.Hash {
|
||||
return rt.merkleHashAllClaims(rt.Root)
|
||||
if h := rt.merkleHashAllClaims(rt.Root); h == nil {
|
||||
return EmptyTrieHash
|
||||
}
|
||||
return rt.Root.merkleHash
|
||||
}
|
||||
|
||||
func (rt *RamTrie) merkleHashAllClaims(v *collapsedVertex) *chainhash.Hash {
|
||||
|
|
|
@ -36,10 +36,10 @@ func SetNetwork(net wire.BitcoinNet) {
|
|||
case wire.TestNet3:
|
||||
OriginalClaimExpirationTime = 262974
|
||||
ExtendedClaimExpirationTime = 2102400
|
||||
ExtendedClaimExpirationForkHeight = 1
|
||||
MaxRemovalWorkaroundHeight = 100
|
||||
NormalizedNameForkHeight = 1
|
||||
AllClaimsInMerkleForkHeight = 109
|
||||
ExtendedClaimExpirationForkHeight = 278160
|
||||
MaxRemovalWorkaroundHeight = 1 // if you get a hash mismatch, come back to this
|
||||
NormalizedNameForkHeight = 993380
|
||||
AllClaimsInMerkleForkHeight = 1198559
|
||||
case wire.TestNet, wire.SimNet: // "regtest"
|
||||
OriginalClaimExpirationTime = 500
|
||||
ExtendedClaimExpirationTime = 600
|
||||
|
|
|
@ -1293,9 +1293,16 @@ func (sm *SyncManager) handleInvMsg(imsg *invMsg) {
|
|||
break
|
||||
}
|
||||
}
|
||||
|
||||
e := wire.BaseEncoding
|
||||
// we think that the iv.Type set above is sufficient. If not:
|
||||
// if peer.IsWitnessEnabled() {
|
||||
// e = wire.WitnessEncoding
|
||||
//}
|
||||
|
||||
state.requestQueue = requestQueue
|
||||
if len(gdmsg.InvList) > 0 {
|
||||
peer.QueueMessage(gdmsg, nil)
|
||||
peer.QueueMessageWithEncoding(gdmsg, nil, e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2226,9 +2226,15 @@ func newPeerBase(origCfg *Config, inbound bool) *Peer {
|
|||
cfg.TrickleInterval = DefaultTrickleInterval
|
||||
}
|
||||
|
||||
encoding := wire.BaseEncoding
|
||||
// we think this gets overwritten downstream. If not:
|
||||
// if cfg.Services&wire.SFNodeWitness > 0 {
|
||||
// encoding = wire.WitnessEncoding
|
||||
//}
|
||||
|
||||
p := Peer{
|
||||
inbound: inbound,
|
||||
wireEncoding: wire.BaseEncoding,
|
||||
wireEncoding: encoding,
|
||||
knownInventory: lru.NewCache(maxKnownInventory),
|
||||
stallControl: make(chan stallControlMsg, 1), // nonblocking sync
|
||||
outputQueue: make(chan outMsg, outputBufferSize),
|
||||
|
|
|
@ -1294,6 +1294,7 @@ func handleGetBlockChainInfo(s *rpcServer, cmd interface{}, closeChan <-chan str
|
|||
Bit: deploymentDetails.BitNumber,
|
||||
StartTime2: int64(deploymentDetails.StartTime),
|
||||
Timeout: int64(deploymentDetails.ExpireTime),
|
||||
Since: deploymentDetails.ForceActiveAt,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue