Skip to content
Snippets Groups Projects

[fix] #1277 G1-Test is stuck because of wrong generated blocks (chained transactions)

Merged [fix] #1277 G1-Test is stuck because of wrong generated blocks (chained transactions)
Merged Cédric Moreau requested to merge 1277_fix into 1.6
4 files
+ 29
18
Compare changes
  • Side-by-side
  • Inline

Files

+ 11
5
@@ -9,6 +9,7 @@ import {CommonConstants} from "../common-libs/constants"
import {IdentityDTO} from "../dto/IdentityDTO"
import {hashf} from "../common"
import {Indexer} from "../indexer"
import {DBTx} from "../dal/sqliteDAL/TxsDAL"
const _ = require('underscore')
@@ -80,7 +81,7 @@ export const GLOBAL_RULES_FUNCTIONS = {
return true;
},
checkSourcesAvailability: async (block:{ transactions:TransactionDTO[], medianTime: number }, conf:ConfDTO, dal:FileDAL, alsoCheckPendingTransactions:boolean) => {
checkSourcesAvailability: async (block:{ transactions:TransactionDTO[], medianTime: number }, conf:ConfDTO, dal:FileDAL, findSourceTx:(txHash:string) => Promise<DBTx|null>) => {
const txs = block.transactions
const current = await dal.getCurrentBlockOrNull();
for (const tx of txs) {
@@ -98,12 +99,12 @@ export const GLOBAL_RULES_FUNCTIONS = {
let src = inputs[k];
let dbSrc = await dal.getSource(src.identifier, src.pos);
logger.debug('Source %s:%s:%s:%s = %s', src.amount, src.base, src.identifier, src.pos, dbSrc && dbSrc.consumed);
if (!dbSrc && alsoCheckPendingTransactions) {
if (!dbSrc) {
// For chained transactions which are checked on sandbox submission, we accept them if there is already
// a previous transaction of the chain already recorded in the pool
dbSrc = await (async () => {
let hypotheticSrc:any = null;
let targetTX = await dal.getTxByHash(src.identifier);
let targetTX = await findSourceTx(src.identifier);
if (targetTX) {
let outputStr = targetTX.outputs[src.pos];
if (outputStr) {
@@ -193,10 +194,15 @@ export const GLOBAL_RULES_HELPERS = {
checkExistsPubkey: (pub:string, dal:FileDAL) => dal.getWrittenIdtyByPubkey(pub),
checkSingleTransaction: (tx:TransactionDTO, block:{ medianTime: number }, conf:ConfDTO, dal:FileDAL, alsoCheckPendingTransactions:boolean = false) => GLOBAL_RULES_FUNCTIONS.checkSourcesAvailability({
checkSingleTransaction: (
tx:TransactionDTO,
block:{ medianTime: number },
conf:ConfDTO,
dal:FileDAL,
findSourceTx:(txHash:string) => Promise<DBTx|null>) => GLOBAL_RULES_FUNCTIONS.checkSourcesAvailability({
transactions: [tx],
medianTime: block.medianTime
}, conf, dal, alsoCheckPendingTransactions),
}, conf, dal, findSourceTx),
checkTxBlockStamp: async (tx:TransactionDTO, dal:FileDAL) => {
const number = parseInt(tx.blockstamp.split('-')[0])
Loading