Skip to content
Snippets Groups Projects
Commit cde67e48 authored by Éloïs's avatar Éloïs
Browse files

Merge branch '1277_fix' into '1.6'

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

Closes #1277

See merge request !1248
parents 62a7d6c1 f97e182e
No related branches found
No related tags found
1 merge request!1248[fix] #1277 G1-Test is stuck because of wrong generated blocks (chained transactions)
......@@ -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])
......
......@@ -105,7 +105,6 @@ export class BlockGenerator {
}
private async findTransactions(current:DBBlock, options:{ dontCareAboutChaining?:boolean }) {
const ALSO_CHECK_PENDING_TXS = true
const versionMin = current ? Math.min(CommonConstants.LAST_VERSION_FOR_TX, current.version) : CommonConstants.DOCUMENTS_VERSION;
const txs = await this.dal.getTransactionsPending(versionMin);
const transactions = [];
......@@ -116,7 +115,9 @@ export class BlockGenerator {
try {
await LOCAL_RULES_HELPERS.checkBunchOfTransactions(passingTxs.concat(tx), this.conf, options)
const nextBlockWithFakeTimeVariation = { medianTime: current.medianTime + 1 };
await GLOBAL_RULES_HELPERS.checkSingleTransaction(tx, nextBlockWithFakeTimeVariation, this.conf, this.dal, ALSO_CHECK_PENDING_TXS);
await GLOBAL_RULES_HELPERS.checkSingleTransaction(tx, nextBlockWithFakeTimeVariation, this.conf, this.dal, async (txHash:string) => {
return _.findWhere(passingTxs, { hash: txHash }) || null
});
await GLOBAL_RULES_HELPERS.checkTxBlockStamp(tx, this.dal);
transactions.push(tx);
passingTxs.push(tx);
......
import {IdentityForRequirements} from './BlockchainService';
"use strict";
import {Server} from "../../server"
import {GlobalFifoPromise} from "./GlobalFifoPromise"
import {BlockchainContext} from "../lib/computation/BlockchainContext"
......@@ -7,7 +6,6 @@ import {ConfDTO} from "../lib/dto/ConfDTO"
import {FileDAL} from "../lib/dal/fileDAL"
import {QuickSynchronizer} from "../lib/computation/QuickSync"
import {BlockDTO} from "../lib/dto/BlockDTO"
import {DBIdentity} from "../lib/dal/sqliteDAL/IdentityDAL"
import {DBBlock} from "../lib/db/DBBlock"
import {GLOBAL_RULES_HELPERS} from "../lib/rules/global_rules"
import {parsers} from "../lib/common-libs/parsers/index"
......@@ -18,6 +16,8 @@ import {LOCAL_RULES_FUNCTIONS} from "../lib/rules/local_rules"
import {Switcher, SwitcherDao} from "../lib/blockchain/Switcher"
import {OtherConstants} from "../lib/other_constants"
"use strict";
const _ = require('underscore');
const constants = require('../lib/constants');
......@@ -206,6 +206,11 @@ export class BlockchainService extends FIFOService {
while (!added && i < potentials.length) {
const dto = BlockDTO.fromJSONObject(potentials[i])
try {
if (dto.issuer === this.conf.pair.pub) {
for (const tx of dto.transactions) {
await this.dal.removeTxByHash(tx.hash);
}
}
const addedBlock = await this.mainContext.checkAndAddBlock(dto)
added = true
this.push({
......
......@@ -9,7 +9,6 @@ import {FIFOService} from "./FIFOService";
import {GlobalFifoPromise} from "./GlobalFifoPromise";
const constants = require('../lib/constants');
const CHECK_PENDING_TRANSACTIONS = true
export class TransactionService extends FIFOService {
......@@ -43,7 +42,7 @@ export class TransactionService extends FIFOService {
const dto = TransactionDTO.fromJSONObject(tx)
await LOCAL_RULES_HELPERS.checkSingleTransactionLocally(dto, this.conf)
await GLOBAL_RULES_HELPERS.checkTxBlockStamp(tx, this.dal);
await GLOBAL_RULES_HELPERS.checkSingleTransaction(dto, nextBlockWithFakeTimeVariation, this.conf, this.dal, CHECK_PENDING_TRANSACTIONS);
await GLOBAL_RULES_HELPERS.checkSingleTransaction(dto, nextBlockWithFakeTimeVariation, this.conf, this.dal, this.dal.getTxByHash.bind(this.dal));
const server_pubkey = this.conf.pair && this.conf.pair.pub;
if (!(await this.dal.txsDAL.sandbox.acceptNewSandBoxEntry({
issuers: tx.issuers,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment