Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore immature txs #234

Merged
merged 7 commits into from Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions scripts/Activity.vue
Expand Up @@ -161,9 +161,10 @@ async function parseTXs(arrTXs) {
// Update the time cache
prevTimestamp = cTx.time * 1000;

// Coinbase Transactions (rewards) require 100 confs
// Coinbase Transactions (rewards) require coinbaseMaturity confs
const fConfirmed =
cNet.cachedBlockCount - cTx.blockHeight >= props.rewards ? 100 : 6;
cNet.cachedBlockCount - cTx.blockHeight >=
(props.rewards ? cChainParams.current.coinbaseMaturity : 6);

// Choose the content type, for the Dashboard; use a generative description, otherwise, a TX-ID
// let txContent = props.rewards ? cTx.id : 'Block Reward';
Expand Down
2 changes: 2 additions & 0 deletions scripts/chain_params.js
Expand Up @@ -46,6 +46,7 @@ export const cChainParams = reactive({
// Network upgrades
UPGRADE_V6_0: undefined,
},
coinbaseMaturity: 100,
budgetCycleBlocks: 43200,
proposalFee: 50 * COIN,
proposalFeeConfirmRequirement: 6,
Expand Down Expand Up @@ -77,6 +78,7 @@ export const cChainParams = reactive({
// Network upgrades
UPGRADE_V6_0: undefined,
},
coinbaseMaturity: 15,
budgetCycleBlocks: 144,
proposalFee: 50 * COIN,
proposalFeeConfirmRequirement: 3,
Expand Down
27 changes: 26 additions & 1 deletion scripts/mempool.js
Expand Up @@ -7,7 +7,7 @@ import {
import { getEventEmitter } from './event_bus.js';
import Multimap from 'multimap';
import { wallet } from './wallet.js';
import { COIN } from './chain_params.js';
import { COIN, cChainParams } from './chain_params.js';

export class CTxOut {
/**
Expand All @@ -27,6 +27,9 @@ export class CTxOut {
* @type {Number} */
this.value = value;
}
isEmpty() {
return this.value == 0 && this.script == 'f8';
}
}
export class CTxIn {
/**
Expand Down Expand Up @@ -69,6 +72,22 @@ export class Transaction {
isConfirmed() {
return this.blockHeight != -1;
}
isCoinStake() {
return this.vout.length >= 2 && this.vout[0].isEmpty();
}
isCoinBase() {
// txid undefined happens only for coinbase inputs
return this.vin.length == 1 && this.vin[0].outpoint.txid === undefined;
panleone marked this conversation as resolved.
Show resolved Hide resolved
}
isMature() {
if (!(this.isCoinBase() || this.isCoinStake())) {
return true;
}
return (
getNetwork().cachedBlockCount - this.blockHeight >
cChainParams.current.coinbaseMaturity
);
}
}
/** An Unspent Transaction Output, used as Inputs of future transactions */
export class COutpoint {
Expand Down Expand Up @@ -228,6 +247,9 @@ export class Mempool {
getBalance(filter) {
let totBalance = 0;
for (const [_, tx] of this.txmap) {
if (!tx.isMature()) {
continue;
}
for (const vout of tx.vout) {
if (this.isSpent(vout.outpoint)) {
continue;
Expand Down Expand Up @@ -285,6 +307,9 @@ export class Mempool {
if (onlyConfirmed && !tx.isConfirmed()) {
continue;
}
if (!tx.isMature()) {
continue;
}
for (const vout of tx.vout) {
if (this.isSpent(vout.outpoint)) {
continue;
Expand Down