mirror of
https://github.com/FlipsideCrypto/dcrd.git
synced 2026-02-06 19:06:51 +00:00
This updates all code in the main module to use the latest major modules
versions to pull in the latest updates.
A more general high level overview of the changes is provided below,
however, there is one semantic change worth calling out independently.
The verifymessage RPC will now return an error when provided with
an address that is not for the current active network and the RPC server
version has been bumped accordingly.
Previously, it would return false which indicated the signature is
invalid, even when the provided signature was actually valid for the
other network. Said behavior was not really incorrect since the
address, signature, and message combination is in fact invalid for the
current active network, however, that result could be somewhat
misleading since a false result could easily be interpreted to mean the
signature is actually invalid altogether which is distinct from the case
of the address being for a different network. Therefore, it is
preferable to explicitly return an error in the case of an address on
the wrong network to cleanly separate these cases.
The following is a high level overview of the changes:
- Replace all calls to removed blockchain merkle root, pow, subsidy, and
coinbase funcs with their standalone module equivalents
- Introduce a new local func named calcTxTreeMerkleRoot that accepts
dcrutil.Tx as before and defers to the new standalone func
- Update block locator handling to match the new signature required by
the peer/v2 module
- Introduce a new local func named chainBlockLocatorToHashes which
performs the necessary conversion
- Update all references to old v1 chaincfg params global instances to
use the new v2 functions
- Modify all cases that parse addresses to provide the now required
current network params
- Include address params with the wsClientFilter
- Replace removed v1 chaincfg constants with local constants
- Create subsidy cache during server init and pass it to the relevant
subsystems
- blockManagerConfig
- BlkTmplGenerator
- rpcServer
- VotingWallet
- Update mining code that creates the block one coinbase transaction to
create the output scripts as defined in the v2 params
- Replace old v2 dcrjson constant references with new types module
- Fix various comment typos
- Update fees module to use the latest major module versions and bump it v2
129 lines
4.1 KiB
Go
129 lines
4.1 KiB
Go
// Copyright (c) 2016 The btcsuite developers
|
|
// Copyright (c) 2015-2019 The Decred developers
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package main
|
|
|
|
import (
|
|
"container/heap"
|
|
"math/rand"
|
|
"testing"
|
|
|
|
"github.com/decred/dcrd/blockchain/stake/v2"
|
|
)
|
|
|
|
// TestStakeTxFeePrioHeap tests the priority heaps including the stake types for
|
|
// both transaction fees per KB and transaction priority. It ensures that the
|
|
// primary sorting is first by stake type, and then by the latter chosen priority
|
|
// type.
|
|
func TestStakeTxFeePrioHeap(t *testing.T) {
|
|
numElements := 1000
|
|
numEdgeConditionElements := 12
|
|
// Create some fake priority items that exercise the expected sort
|
|
// edge conditions.
|
|
testItems := []*txPrioItem{
|
|
{feePerKB: 5678, txType: stake.TxTypeRegular, priority: 3},
|
|
{feePerKB: 5678, txType: stake.TxTypeRegular, priority: 1},
|
|
{feePerKB: 5678, txType: stake.TxTypeRegular, priority: 1}, // Duplicate fee and prio
|
|
{feePerKB: 5678, txType: stake.TxTypeRegular, priority: 5},
|
|
{feePerKB: 5678, txType: stake.TxTypeRegular, priority: 2},
|
|
{feePerKB: 1234, txType: stake.TxTypeRegular, priority: 3},
|
|
{feePerKB: 1234, txType: stake.TxTypeRegular, priority: 1},
|
|
{feePerKB: 1234, txType: stake.TxTypeRegular, priority: 5},
|
|
{feePerKB: 1234, txType: stake.TxTypeRegular, priority: 5}, // Duplicate fee and prio
|
|
{feePerKB: 1234, txType: stake.TxTypeRegular, priority: 2},
|
|
{feePerKB: 10000, txType: stake.TxTypeRegular, priority: 0}, // Higher fee, smaller prio
|
|
{feePerKB: 0, txType: stake.TxTypeRegular, priority: 10000}, // Higher prio, lower fee
|
|
}
|
|
ph := newTxPriorityQueue((numElements + numEdgeConditionElements), txPQByStakeAndFee)
|
|
|
|
// Add random data in addition to the edge conditions already manually
|
|
// specified.
|
|
for i := 0; i < (numElements + numEdgeConditionElements); i++ {
|
|
if i >= numEdgeConditionElements {
|
|
randType := stake.TxType(rand.Intn(4))
|
|
randPrio := rand.Float64() * 100
|
|
randFeePerKB := rand.Float64() * 10
|
|
testItems = append(testItems, &txPrioItem{
|
|
tx: nil,
|
|
txType: randType,
|
|
feePerKB: randFeePerKB,
|
|
priority: randPrio,
|
|
})
|
|
}
|
|
|
|
heap.Push(ph, testItems[i])
|
|
}
|
|
|
|
// Test sorting by stake and fee per KB.
|
|
last := &txPrioItem{
|
|
tx: nil,
|
|
txType: stake.TxTypeSSGen,
|
|
priority: 10000.0,
|
|
feePerKB: 10000.0,
|
|
}
|
|
for i := 0; i < numElements; i++ {
|
|
prioItem := heap.Pop(ph)
|
|
txpi, ok := prioItem.(*txPrioItem)
|
|
if ok {
|
|
if txpi.feePerKB > last.feePerKB &&
|
|
compareStakePriority(txpi, last) >= 0 {
|
|
t.Errorf("bad pop: %v fee per KB was more than last of %v "+
|
|
"while the txtype was %v but last was %v",
|
|
txpi.feePerKB, last.feePerKB, txpi.txType, last.txType)
|
|
}
|
|
last = txpi
|
|
}
|
|
}
|
|
|
|
ph = newTxPriorityQueue(len(testItems), txPQByStakeAndFeeAndThenPriority)
|
|
for i := 0; i < numElements; i++ {
|
|
randType := stake.TxType(rand.Intn(4))
|
|
randPrio := rand.Float64() * 100
|
|
randFeePerKB := rand.Float64() * 10
|
|
prioItem := &txPrioItem{
|
|
tx: nil,
|
|
txType: randType,
|
|
feePerKB: randFeePerKB,
|
|
priority: randPrio,
|
|
}
|
|
heap.Push(ph, prioItem)
|
|
}
|
|
|
|
// Test sorting with fees per KB for high stake priority, then
|
|
// priority for low stake priority.
|
|
last = &txPrioItem{
|
|
tx: nil,
|
|
txType: stake.TxTypeSSGen,
|
|
priority: 10000.0,
|
|
feePerKB: 10000.0,
|
|
}
|
|
for i := 0; i < numElements; i++ {
|
|
prioItem := heap.Pop(ph)
|
|
txpi, ok := prioItem.(*txPrioItem)
|
|
if ok {
|
|
bothAreLowStakePriority :=
|
|
txStakePriority(txpi.txType) == regOrRevocPriority &&
|
|
txStakePriority(last.txType) == regOrRevocPriority
|
|
if !bothAreLowStakePriority {
|
|
if txpi.feePerKB > last.feePerKB &&
|
|
compareStakePriority(txpi, last) >= 0 {
|
|
t.Errorf("bad pop: %v fee per KB was more than last of %v "+
|
|
"while the txtype was %v but last was %v",
|
|
txpi.feePerKB, last.feePerKB, txpi.txType, last.txType)
|
|
}
|
|
}
|
|
if bothAreLowStakePriority {
|
|
if txpi.priority > last.priority &&
|
|
compareStakePriority(txpi, last) >= 0 {
|
|
t.Errorf("bad pop: %v priority was more than last of %v "+
|
|
"while the txtype was %v but last was %v",
|
|
txpi.feePerKB, last.feePerKB, txpi.txType, last.txType)
|
|
}
|
|
}
|
|
last = txpi
|
|
}
|
|
}
|
|
}
|