Commit 9895862c authored by Éloïs's avatar Éloïs

[fix] transactions check: auto use new verify fn when dubp jump to v12

parent 9f7afef8
......@@ -13,7 +13,7 @@
import {hashf} from "../common"
import {Cloneable} from "./Cloneable"
import {verifyBuggy} from "../common-libs/crypto/keyring"
import {verify, verifyBuggy} from "../common-libs/crypto/keyring"
export interface BaseDTO {
base: number
......@@ -237,7 +237,7 @@ export class TransactionDTO implements Cloneable {
}
}
getTransactionSigResult() {
getTransactionSigResult(dubp_version: number) {
const sigResult = new TxSignatureResultImpl(this.issuers.slice())
let i = 0
const raw = this.getRawTxNoSig()
......@@ -245,14 +245,19 @@ export class TransactionDTO implements Cloneable {
while (matching && i < this.signatures.length) {
const sig = this.signatures[i]
const pub = this.issuers[i]
sigResult.sigs[i].ok = matching = verifyBuggy(raw, sig, pub)
if (dubp_version >= 12) {
sigResult.sigs[i].ok = verify(raw, sig, pub)
} else {
sigResult.sigs[i].ok = verifyBuggy(raw, sig, pub)
}
matching = sigResult.sigs[i].ok
i++
}
return sigResult
}
checkSignatures() {
return this.getTransactionSigResult().allMatching
checkSignatures(dubp_version: number) {
return this.getTransactionSigResult(dubp_version).allMatching
}
static fromJSONObject(obj:any, currency:string = "") {
......
......@@ -2160,7 +2160,7 @@ function txSourceUnlock(ENTRY:SindexEntry, source:{ conditions: string, written_
const tx = ENTRY.txObj;
const unlockParams:string[] = TransactionDTO.unlock2params(ENTRY.unlock || '')
const unlocksMetadata:UnlockMetadata = {}
const sigResult = TransactionDTO.fromJSONObject(tx).getTransactionSigResult()
const sigResult = TransactionDTO.fromJSONObject(tx).getTransactionSigResult(HEAD.version)
if (!source.conditions) {
return false // Unlock fail
}
......
......@@ -94,7 +94,7 @@ export const GLOBAL_RULES_FUNCTIONS = {
return true;
},
checkSourcesAvailability: async (block:{ transactions:TransactionDTO[], medianTime: number }, conf:ConfDTO, dal:FileDAL, findSourceTx:(txHash:string) => Promise<DBTx|null>) => {
checkSourcesAvailability: async (block:{ version: number, 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) {
......@@ -150,7 +150,7 @@ export const GLOBAL_RULES_FUNCTIONS = {
unlocksMetadata.elapsedTime = block.medianTime - dbSrc.written_time;
}
const sigs = tx.getTransactionSigResult()
const sigs = tx.getTransactionSigResult(block.version)
try {
if (!txunlock(dbSrc.conditions, unlocksForCondition, sigs, unlocksMetadata)) {
......@@ -213,13 +213,18 @@ export const GLOBAL_RULES_HELPERS = {
checkSingleTransaction: (
tx:TransactionDTO,
block:{ medianTime: number },
dubp_version: number,
medianTime: number,
conf:ConfDTO,
dal:FileDAL,
findSourceTx:(txHash:string) => Promise<DBTx|null>) => GLOBAL_RULES_FUNCTIONS.checkSourcesAvailability({
transactions: [tx],
medianTime: block.medianTime
}, conf, dal, findSourceTx),
findSourceTx:(txHash:string) => Promise<DBTx|null>) => GLOBAL_RULES_FUNCTIONS.checkSourcesAvailability(
{
version: dubp_version,
transactions: [tx],
medianTime: medianTime
},
conf, dal, findSourceTx
),
checkTxBlockStamp: async (tx:TransactionDTO, dal:FileDAL) => {
const number = parseInt(tx.blockstamp.split('-')[0])
......
......@@ -390,7 +390,7 @@ export const LOCAL_RULES_FUNCTIONS = {
const txs = block.transactions
// Check rule against each transaction
for (const tx of txs) {
if (!tx.checkSignatures()) {
if (!tx.checkSignatures(block.version)) {
throw Error('Signature from a transaction must match')
}
}
......
......@@ -144,8 +144,8 @@ export class BlockGenerator {
const tx = TransactionDTO.fromJSONObject(obj);
try {
await LOCAL_RULES_HELPERS.checkBunchOfTransactions(passingTxs.concat(tx), this.conf, medianTime, options)
const nextBlockWithFakeTimeVariation = { medianTime: current.medianTime + 1 };
await GLOBAL_RULES_HELPERS.checkSingleTransaction(tx, nextBlockWithFakeTimeVariation, this.conf, this.dal, async (txHash:string) => {
const fakeTimeVariation = current.medianTime + 1;
await GLOBAL_RULES_HELPERS.checkSingleTransaction(tx, current.version, fakeTimeVariation, this.conf, this.dal, async (txHash:string) => {
return Underscore.findWhere(passingTxs, { hash: txHash }) || null
});
await GLOBAL_RULES_HELPERS.checkTxBlockStamp(tx, this.dal);
......
......@@ -54,11 +54,11 @@ export class TransactionService extends FIFOService {
throw constants.ERRORS.TX_ALREADY_PROCESSED;
}
// Start checks...
const nextBlockWithFakeTimeVariation = { medianTime: current.medianTime + 1 };
const fakeTimeVariation = current.medianTime + 1;
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, this.dal.getTxByHash.bind(this.dal));
await GLOBAL_RULES_HELPERS.checkSingleTransaction(dto, current.version, fakeTimeVariation, 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,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment