LiskArchive / lisk-sdk

🔩 Lisk software development kit
https://lisk.com
Apache License 2.0
2.72k stars 454 forks source link

Node fail to sync when block contains multisignature transaction #3612

Closed 4miners closed 5 years ago

4miners commented 5 years ago

Expected behavior

The node should be able to sync when a block contains multisignature registration transaction.

Actual behavior

It fails with following message:

14:03:52.617Z  INFO lisk-framework: Block 5753985202868417271 loaded from the network height: 17
14:03:52.625Z DEBUG lisk-framework:
    Block processing failed { id: '1354458273227907673',
      err:
       'Transaction: 4767118963976999553 failed at .multisignature.keysgroup: \'.multisignature.keysgroup\' should NOT have fewer than 1 items',
      module: 'blocks',
      block:
       { id: '1354458273227907673',
         version: 1,
         timestamp: 93719360,
         height: 18,
         previousBlock: '5753985202868417271',
         numberOfTransactions: 10,
         totalAmount: 0,
         totalFee: 15000000000,
         reward: 0,
         payloadLength: 3130,
         payloadHash:
          '7377aae41a8af606f505d18c63ce6994bf04c1844f192a87c822aaf35e6ca526',
         generatorPublicKey:
          '85b07e51ffe528f272b7eb734d0496158f2b0f890155ebe59ba2989a8ccc9a49',
         generatorId: '6214967903930344618L',
         blockSignature:
          'f8670420bd65a232723d6e1b4de4266e9fe05e67ecb1821a7e4d53c5c0cd31a2da048899631b70fff50f2ff1f774a42ec9470f14b30d2861a7acefa55894ee08',
         confirmations: NaN,
         totalForged: '15000000000',
         transactions:
          [ [MultisignatureTransaction],
            [MultisignatureTransaction],
            [MultisignatureTransaction],
            [MultisignatureTransaction],
            [MultisignatureTransaction],
            [MultisignatureTransaction],
            [MultisignatureTransaction],
            [MultisignatureTransaction],
            [MultisignatureTransaction],
            [MultisignatureTransaction] ] } }
14:03:52.628Z DEBUG lisk-framework: Perform chain recovery due to poor consensus
14:03:52.628Z  WARN lisk-framework: Chain comparison failed, starting recovery

Steps to reproduce

Check logs on fra1-alpha2-001.liskdev.net machine.

Which version(s) does this affect? (Environment, OS, etc...)

2.0.0-alpha.2

4miners commented 5 years ago

Note: The below mentioned logs are from 2.0.0 node

The issue is back:

11:41:58.784Z  INFO lisk-framework: Block 15910358440661876618 loaded from the network height: 19
11:41:58.787Z DEBUG lisk-framework:
    Block processing failed { id: '16924785937353391122',
      err:
       'Transaction: 6536698525891138804 failed at .multisignature.keysgroup: \'.multisignature.keysgroup\' should NOT have fewer than 1 items',
      module: 'blocks',
      block:
       { id: '16924785937353391122',
         version: 1,
         timestamp: 97979230,
         height: 20,
         previousBlock: '15910358440661876618',
         numberOfTransactions: 1,
         totalAmount: 0,
         totalFee: 1500000000,
         reward: 0,
         payloadLength: 249,
         payloadHash:
          'f4948f27ad04b75afefda6eac4b35e15c058c11834d410330b8ce89313502d06',
         generatorPublicKey:
          '03e811dda4f51323ac712cd12299410830d655ddffb104f2c9974d90bf8c583a',
         generatorId: '11506830473925742632L',
         blockSignature:
          '40c13f018eb570716dc91c3075821657510682e52f04ca7dd2d0810732510edee6251101afb7d500541af8aca25d1fc66c185771f6a4d3419f8c8227d3da8e04',
         confirmations: 0,
         totalForged: '1500000000',
         transactions: [ [MultisignatureTransaction] ] } }

Transaction: http://jenkinsnet-19-seed-01.liskdev.net:6040/tx/6536698525891138804

Steps to reproduce

Sync with the network that have multisignature creation transaction (type 4).

Which version(s) does this affect? (Environment, OS, etc...)

release/2.0.0

4miners commented 5 years ago

We receive a response from a 1.6.0 peer in following format:

m_keysgroup:
           [ '+bded9e57535342cb833f6cd1186d3719a185c6258ce41dd70de5dc95aa6a43c9',
             '+8b6ba7434a7d3d327cacd9fadc04d70f465ae3559d8a4a55f17842cd646c9d1c' ],

Then the flow is following: modules.blocks.process.loadBlocksFromNetwork -> modules.blocks.utils.readDbRows -> logic.initTransaction.dbRead -> base_transaction.ts @ fromSync

Then we finally call: https://github.com/LiskHQ/lisk-sdk/blob/0711c1d3b9e45886d8d42ea3cd6bc1d565f884e7/elements/lisk-transactions/src/4_multisignature_transaction.ts#L393-L408

In case when raw.m_keysgroup is not a string it will set empty array for keysgroup property. The bug is fixed if we change the logic to something like:

    protected assetFromSync(raw: any): object | undefined {
        if (!raw.m_keysgroup) {
            return undefined;
        }
        const multisignature = {
            min: raw.m_min,
            lifetime: raw.m_lifetime,
        };

        if (typeof raw.m_keysgroup === 'string') {
            multisignature.keysgroup = raw.m_keysgroup.split(',');
        } else {
            multisignature.keysgroup = raw.m_keysgroup ? raw.m_keysgroup : [];
        }

        return { multisignature };
}