mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-09-15 22:10:12 +00:00

* UTXO dump of block 0fca37ca667c2d550a6c4416dad9717e50927128c424fa4edbebc436ab13aeef * Activate HF immediately and change reward to 1000 * Change protocol version and datadir location * Delete comments * Fix zero hash to muhash zero hash in genesis utxo dump check * Don't omit genesis as direct parent * Fix tests * Change subsidy to 500 * Dont assume genesis multiset is empty * Fix BlockReward test * Fix TestValidateAndInsertImportedPruningPoint test * Fix pruning point genesis utxo set * Fix tests related to mainnet utxo set * Dont change the difficulty before you have a full window * Fix TestBlockWindow tests * Remove global utxo set variable, and persist mainnetnet utxo deserialization between runs * Fix last tests * Make peer banning opt-in * small fix for a test * Fix go lint * Fix Ori's review comments * Change DAA score of genesis to checkpoint DAA score and fix all tests * Fix the BlockLevel bits counting * Fix some tests and make them run a little faster * Change datadir name back to kaspa-mainnet and change db path from /data to /datadir * Last changes for the release and change the version to 0.11.5 Co-authored-by: Ori Newman <orinewman1@gmail.com> Co-authored-by: Ori Newman <> Co-authored-by: msutton <mikisiton2@gmail.com>
91 lines
3.7 KiB
Go
91 lines
3.7 KiB
Go
package coinbasemanager_test
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/domain/consensus"
|
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
|
"github.com/kaspanet/kaspad/domain/consensus/utils/constants"
|
|
"github.com/kaspanet/kaspad/domain/consensus/utils/testutils"
|
|
"github.com/kaspanet/kaspad/domain/consensus/utils/transactionhelper"
|
|
"github.com/kaspanet/kaspad/util/difficulty"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestBlockRewardSwitch(t *testing.T) {
|
|
testutils.ForAllNets(t, true, func(t *testing.T, consensusConfig *consensus.Config) {
|
|
// Set the pruning depth to 10
|
|
consensusConfig.MergeSetSizeLimit = 1
|
|
consensusConfig.K = 1
|
|
consensusConfig.FinalityDuration = 1 * time.Second
|
|
consensusConfig.TargetTimePerBlock = 1 * time.Second
|
|
|
|
// Disable difficulty adjustment so that we could reason about blue work
|
|
consensusConfig.DisableDifficultyAdjustment = true
|
|
|
|
// Disable pruning so that we could have access to all the blocks
|
|
consensusConfig.IsArchival = true
|
|
|
|
// Set the interval to 10
|
|
consensusConfig.FixedSubsidySwitchPruningPointInterval = 10
|
|
|
|
// Set the hash rate difference such that the switch would trigger exactly
|
|
// on the `FixedSubsidySwitchPruningPointInterval + 1`th pruning point
|
|
workToAcceptGenesis := difficulty.CalcWork(consensusConfig.GenesisBlock.Header.Bits())
|
|
consensusConfig.FixedSubsidySwitchHashRateThreshold = workToAcceptGenesis
|
|
|
|
// Set the min, max, and post-switch subsidies to values that would make it
|
|
// easy to tell whether the switch happened
|
|
consensusConfig.MinSubsidy = 2 * constants.SompiPerKaspa
|
|
consensusConfig.MaxSubsidy = 2 * constants.SompiPerKaspa
|
|
consensusConfig.SubsidyGenesisReward = 1 * constants.SompiPerKaspa
|
|
|
|
factory := consensus.NewFactory()
|
|
tc, teardown, err := factory.NewTestConsensus(consensusConfig, "TestBlockRewardSwitch")
|
|
if err != nil {
|
|
t.Fatalf("Error setting up consensus: %+v", err)
|
|
}
|
|
defer teardown(false)
|
|
|
|
// Make the pruning point move FixedSubsidySwitchPruningPointInterval times
|
|
tipHash := consensusConfig.GenesisHash
|
|
for i := uint64(0); i < consensusConfig.PruningDepth()+consensusConfig.FixedSubsidySwitchPruningPointInterval; i++ {
|
|
addedBlockHash, _, err := tc.AddBlock([]*externalapi.DomainHash{tipHash}, nil, nil)
|
|
if err != nil {
|
|
t.Fatalf("AddBlock: %+v", err)
|
|
}
|
|
tipHash = addedBlockHash
|
|
}
|
|
|
|
// We expect to see `FixedSubsidySwitchPruningPointInterval` pruning points + the genesis
|
|
pruningPointHeaders, err := tc.PruningPointHeaders()
|
|
if err != nil {
|
|
t.Fatalf("PruningPointHeaders: %+v", pruningPointHeaders)
|
|
}
|
|
expectedPruningPointHeaderAmount := consensusConfig.FixedSubsidySwitchPruningPointInterval + 1
|
|
if uint64(len(pruningPointHeaders)) != expectedPruningPointHeaderAmount {
|
|
t.Fatalf("Unexpected amount of pruning point headers. "+
|
|
"Want: %d, got: %d", expectedPruningPointHeaderAmount, len(pruningPointHeaders))
|
|
}
|
|
|
|
// Make sure that all the headers thus far had a non-fixed subsidies
|
|
// Note that we skip the genesis, since that always has the post-switch
|
|
// value
|
|
for _, pruningPointHeader := range pruningPointHeaders[1:] {
|
|
pruningPointHash := consensushashing.HeaderHash(pruningPointHeader)
|
|
pruningPoint, err := tc.GetBlock(pruningPointHash)
|
|
if err != nil {
|
|
t.Fatalf("GetBlock: %+v", err)
|
|
}
|
|
pruningPointCoinbase := pruningPoint.Transactions[transactionhelper.CoinbaseTransactionIndex]
|
|
_, _, subsidy, err := tc.CoinbaseManager().ExtractCoinbaseDataBlueScoreAndSubsidy(pruningPointCoinbase)
|
|
if err != nil {
|
|
t.Fatalf("ExtractCoinbaseDataBlueScoreAndSubsidy: %+v", err)
|
|
}
|
|
if subsidy != consensusConfig.MinSubsidy {
|
|
t.Fatalf("Subsidy has unexpected value. Want: %d, got: %d", consensusConfig.MinSubsidy, subsidy)
|
|
}
|
|
}
|
|
})
|
|
}
|