Skip to content

Commit

Permalink
Port policy
Browse files Browse the repository at this point in the history
  • Loading branch information
timemarkovqtum committed Feb 14, 2024
1 parent 5408367 commit a6d50f1
Show file tree
Hide file tree
Showing 21 changed files with 413 additions and 77 deletions.
7 changes: 6 additions & 1 deletion src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ struct Params {
{
return std::chrono::seconds{nPowTargetSpacing};
}
int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; }
int64_t DifficultyAdjustmentInterval(int height=0) const
{
int64_t targetTimespan = TargetTimespan(height);
int64_t targetSpacing = TargetSpacing(height);
return targetTimespan / targetSpacing;
}
/** The best chain should have at least this much work */
uint256 nMinimumChainWork;
/** By default assume that the signatures in ancestors of this block are valid */
Expand Down
168 changes: 166 additions & 2 deletions src/interfaces/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ struct WalletTx;
struct WalletTxOut;
struct WalletTxStatus;
struct WalletMigrationResult;
struct TokenInfo;
struct TokenTx;
struct ContractBookData;
struct DelegationInfo;
struct DelegationDetails;
struct SuperStakerInfo;
struct DelegationStakerInfo;
struct SignDelegation;

using WalletOrderForm = std::vector<std::pair<std::string, std::string>>;
using WalletValueMap = std::map<std::string, std::string>;
Expand Down Expand Up @@ -373,17 +381,19 @@ struct WalletBalances
CAmount balance = 0;
CAmount unconfirmed_balance = 0;
CAmount immature_balance = 0;
CAmount stake = 0;
bool have_watch_only = false;
CAmount watch_only_balance = 0;
CAmount unconfirmed_watch_only_balance = 0;
CAmount immature_watch_only_balance = 0;
CAmount watch_only_stake = 0;

bool balanceChanged(const WalletBalances& prev) const
{
return balance != prev.balance || unconfirmed_balance != prev.unconfirmed_balance ||
immature_balance != prev.immature_balance || watch_only_balance != prev.watch_only_balance ||
immature_balance != prev.immature_balance || stake != prev.stake || watch_only_balance != prev.watch_only_balance ||
unconfirmed_watch_only_balance != prev.unconfirmed_watch_only_balance ||
immature_watch_only_balance != prev.immature_watch_only_balance;
immature_watch_only_balance != prev.immature_watch_only_balance || watch_only_stake != prev.watch_only_stake;
}
};

Expand All @@ -402,6 +412,13 @@ struct WalletTx
int64_t time;
std::map<std::string, std::string> value_map;
bool is_coinbase;
bool is_coinstake;
bool is_in_main_chain;

// Contract tx params
bool has_create_or_call;
CKeyID tx_sender_key;
std::vector<CKeyID> txout_keys;

bool operator<(const WalletTx& a) const { return tx->GetHash() < a.tx->GetHash(); }
};
Expand All @@ -417,6 +434,7 @@ struct WalletTxStatus
bool is_trusted;
bool is_abandoned;
bool is_coinbase;
bool is_coinstake;
bool is_in_main_chain;
};

Expand All @@ -438,6 +456,152 @@ struct WalletMigrationResult
fs::path backup_path;
};

//! Wallet token information.
struct TokenInfo
{
std::string contract_address;
std::string token_name;
std::string token_symbol;
uint8_t decimals = 0;
std::string sender_address;
int64_t time = 0;
uint256 block_hash;
int64_t block_number = -1;
uint256 hash;
};

//! Wallet token transaction
struct TokenTx
{
std::string contract_address;
std::string sender_address;
std::string receiver_address;
uint256 value;
uint256 tx_hash;
int64_t time = 0;
uint256 block_hash;
int64_t block_number = -1;
std::string label;
uint256 hash;
};

//! Wallet contract book data */
struct ContractBookData
{
std::string address;
std::string name;
std::string abi;
};

//! Wallet delegation information.
struct DelegationInfo
{
std::string delegate_address;
std::string staker_address;
std::string staker_name;
uint8_t fee = 0;
int64_t time = 0;
int64_t block_number = -1;
uint256 hash;
uint256 create_tx_hash;
uint256 remove_tx_hash;
};

//! Delegation details.
struct DelegationDetails
{
// Wallet delegation details
bool w_entry_exist = false;
std::string w_delegate_address;
std::string w_staker_address;
std::string w_staker_name;
uint8_t w_fee = 0;
int64_t w_time = 0;
int64_t w_block_number = -1;
uint256 w_hash;
uint256 w_create_tx_hash;
uint256 w_remove_tx_hash;

// Wallet create tx details
bool w_create_exist = false;
bool w_create_in_main_chain = false;
bool w_create_in_mempool = false;
bool w_create_abandoned = false;

// Wallet remove tx details
bool w_remove_exist = false;
bool w_remove_in_main_chain = false;
bool w_remove_in_mempool = false;
bool w_remove_abandoned = false;

// Delegation contract details
std::string c_delegate_address;
std::string c_staker_address;
uint8_t c_fee = 0;
int64_t c_block_number = -1;
bool c_entry_exist = false;
bool c_contract_return = false;

// To delegation info
DelegationInfo toInfo(bool fromWallet = true)
{
interfaces::DelegationInfo info;
info.delegate_address = fromWallet ? w_delegate_address : c_delegate_address;
info.staker_address = fromWallet ? w_staker_address : c_staker_address;
info.fee = fromWallet ? w_fee : c_fee;
info.block_number = fromWallet ? w_block_number : c_block_number;
info.hash = w_hash;
info.time = w_time;
info.create_tx_hash = w_create_tx_hash;
info.remove_tx_hash = w_remove_tx_hash;
info.staker_name = w_staker_name;
return info;
}
};

// Super staker address list
enum SuperStakerAddressList
{
AcceptAll = 0,
AllowList = 1,
ExcludeList = 2
};

// Wallet super staker information.
struct SuperStakerInfo
{
uint256 hash;
std::string staker_address;
std::string staker_name;
int64_t time = 0;
bool custom_config = false;
uint8_t min_fee = 0;
CAmount min_delegate_utxo = 0;
std::vector<std::string> delegate_address_list;
int delegate_address_type = 0;
};

// Wallet delegation staker information.
struct DelegationStakerInfo
{
std::string delegate_address;
std::string staker_address;
std::string PoD;
uint8_t fee = 0;
int64_t time = 0;
int64_t block_number = -1;
CAmount weight = 0;
uint160 hash;
};

// Sign PoD wallet delegation data.
struct SignDelegation
{
std::string delegate;
std::string staker;
std::string PoD;
};

//! Return implementation of Wallet interface. This function is defined in
//! dummywallet.cpp and throws if the wallet component is not compiled.
std::unique_ptr<Wallet> MakeWallet(wallet::WalletContext& context, const std::shared_ptr<wallet::CWallet>& wallet);
Expand Down
39 changes: 39 additions & 0 deletions src/node/miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,45 @@ namespace Consensus { struct Params; };
namespace node {
static const bool DEFAULT_PRINTPRIORITY = false;

static const bool DEFAULT_STAKE = true;

static const bool DEFAULT_STAKE_CACHE = true;

static const bool DEFAULT_SUPER_STAKE = false;

static const bool ENABLE_HARDWARE_STAKE = false;

//How many seconds to look ahead and prepare a block for staking
//Look ahead up to 3 "timeslots" in the future, 48 seconds
//Reduce this to reduce computational waste for stakers, increase this to increase the amount of time available to construct full blocks
static const int32_t MAX_STAKE_LOOKAHEAD = 16 * 3;

//Will not add any more contracts when GetAdjustedTime() >= nTimeLimit-BYTECODE_TIME_BUFFER
//This does not affect non-contract transactions
static const int32_t BYTECODE_TIME_BUFFER = 6;

//Will not attempt to add more transactions when GetAdjustedTime() >= nTimeLimit
//And nTimeLimit = StakeExpirationTime - STAKE_TIME_BUFFER
static const int32_t STAKE_TIME_BUFFER = 2;

//How often to try to stake blocks in milliseconds
static const int32_t STAKER_POLLING_PERIOD = 5000;

//How often to try to stake blocks in milliseconds for minimum difficulty
static const int32_t STAKER_POLLING_PERIOD_MIN_DIFFICULTY = 20000;

//How often to try to check for future walid block
static const int32_t STAKER_WAIT_FOR_WALID_BLOCK = 3000;

//How much time to wait for best block header to be downloaded to the blockchain
static const int32_t STAKER_WAIT_FOR_BEST_BLOCK_HEADER = 250;

//How much max time to wait for best block header to be downloaded to the blockchain
static const int32_t DEFAULT_MAX_STAKER_WAIT_FOR_BEST_BLOCK_HEADER = 4000;

//How much time to spend trying to process transactions when using the generate RPC call
static const int32_t POW_MINER_MAX_TIME = 60;

struct CBlockTemplate
{
CBlock block;
Expand Down
2 changes: 1 addition & 1 deletion src/policy/feerate.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <string>
#include <type_traits>

const std::string CURRENCY_UNIT = "BTC"; // One formatted unit
const std::string CURRENCY_UNIT = "QTUM"; // One formatted unit
const std::string CURRENCY_ATOM = "sat"; // One indivisible minimum value unit

/* Used to determine type of fee estimation requested */
Expand Down
5 changes: 5 additions & 0 deletions src/policy/fees.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,11 @@ bool CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const CTxM
return false;
}

if(entry->GetTx().HasCreateOrCall()){
//Exclude contract transactions
return false;
}

// How many blocks did it take for miners to include this transaction?
// blocksToConfirm is 1-based, so a transaction included in the earliest
// possible block has confirmation count of 1
Expand Down
2 changes: 1 addition & 1 deletion src/policy/policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFeeIn)

bool IsDust(const CTxOut& txout, const CFeeRate& dustRelayFeeIn)
{
return (txout.nValue < GetDustThreshold(txout, dustRelayFeeIn));
return (txout.nValue < GetDustThreshold(txout, dustRelayFeeIn) && !txout.scriptPubKey.HasOpCreate() && !txout.scriptPubKey.HasOpCall());
}

bool IsStandard(const CScript& scriptPubKey, const std::optional<unsigned>& max_datacarrier_bytes, TxoutType& whichType)
Expand Down
17 changes: 11 additions & 6 deletions src/policy/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ class CFeeRate;
class CScript;

/** Default for -blockmaxweight, which controls the range of block weights the mining code will create **/
static constexpr unsigned int DEFAULT_BLOCK_MAX_WEIGHT{MAX_BLOCK_WEIGHT - 4000};
static constexpr unsigned int DEFAULT_BLOCK_MAX_WEIGHT{7600000};
/** Default for -blockmintxfee, which sets the minimum feerate for a transaction in blocks created by mining code **/
static constexpr unsigned int DEFAULT_BLOCK_MIN_TX_FEE{1000};
static constexpr unsigned int DEFAULT_BLOCK_MIN_TX_FEE{400000};
/** The maximum weight for transactions we're willing to relay/mine */
static constexpr int32_t MAX_STANDARD_TX_WEIGHT{400000};
/** The minimum non-witness size for transactions we're willing to relay/mine: one larger than 64 */
static constexpr unsigned int MIN_STANDARD_TX_NONWITNESS_SIZE{65};
/** Maximum number of signature check operations in an IsStandard() P2SH script */
static constexpr unsigned int MAX_P2SH_SIGOPS{15};
/** The maximum number of sigops we're willing to relay/mine in a single tx */
static constexpr unsigned int MAX_STANDARD_TX_SIGOPS_COST{MAX_BLOCK_SIGOPS_COST/5};
extern unsigned int dgpMaxTxSigOps;
/** Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or replacement **/
static constexpr unsigned int DEFAULT_INCREMENTAL_RELAY_FEE{1000};
static constexpr unsigned int DEFAULT_INCREMENTAL_RELAY_FEE{10000};
/** Default for -bytespersigop */
static constexpr unsigned int DEFAULT_BYTES_PER_SIGOP{20};
/** Default for -permitbaremultisig */
Expand All @@ -52,9 +52,9 @@ static constexpr unsigned int MAX_STANDARD_SCRIPTSIG_SIZE{1650};
* standard and should be done with care and ideally rarely. It makes sense to
* only increase the dust limit after prior releases were already not creating
* outputs below the new threshold */
static constexpr unsigned int DUST_RELAY_TX_FEE{3000};
static constexpr unsigned int DUST_RELAY_TX_FEE{400000};
/** Default for -minrelaytxfee, minimum relay fee for transactions */
static constexpr unsigned int DEFAULT_MIN_RELAY_TX_FEE{1000};
static constexpr unsigned int DEFAULT_MIN_RELAY_TX_FEE{400000};
/** Default for -limitancestorcount, max number of in-mempool ancestors */
static constexpr unsigned int DEFAULT_ANCESTOR_LIMIT{25};
/** Default for -limitancestorsize, maximum kilobytes of tx + all in-mempool ancestors */
Expand Down Expand Up @@ -121,6 +121,11 @@ static constexpr unsigned int STANDARD_NOT_MANDATORY_VERIFY_FLAGS{STANDARD_SCRIP
/** Used as the flags parameter to sequence and nLocktime checks in non-consensus code. */
static constexpr unsigned int STANDARD_LOCKTIME_VERIFY_FLAGS{LOCKTIME_VERIFY_SEQUENCE};

/** The number of sender stack items in a standard sender signature script */
static constexpr unsigned int STANDARD_SENDER_STACK_ITEMS{2};
/** The maximum size of each sender stack item in a standard sender signature script */
static constexpr unsigned int MAX_STANDARD_SENDER_STACK_ITEM_SIZE{80};

CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFee);

bool IsDust(const CTxOut& txout, const CFeeRate& dustRelayFee);
Expand Down
Loading

0 comments on commit a6d50f1

Please sign in to comment.