Skip to content

Fix crash when catching up genesis txns #1187

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

Merged
merged 1 commit into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions plenum/server/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -2179,8 +2179,9 @@ def postTxnFromCatchupAddedToLedger(self, ledger_id: int, txn: Any, updateSeqNo=
state = self.getState(ledger_id)
state.commit(rootHash=state.headHash)
if ledger_id == DOMAIN_LEDGER_ID and rh.ts_store:
rh.ts_store.set(get_txn_time(txn),
state.headHash)
timestamp = get_txn_time(txn)
if timestamp is not None:
rh.ts_store.set(timestamp, state.headHash)
logger.trace("{} added transaction with seqNo {} to ledger {} during catchup, state root {}"
.format(self, get_seq_no(txn), ledger_id,
state_roots_serializer.serialize(bytes(state.committedHeadHash))))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from typing import Optional

from plenum.common.constants import DOMAIN_LEDGER_ID, CURRENT_PROTOCOL_VERSION
from plenum.common.txn_util import reqToTxn
from plenum.test.helper import sdk_random_request_objects


def test_post_genesis_txn_from_catchup_added_to_ledger(looper, txnPoolNodeSet):
node = txnPoolNodeSet[0]

def add_txn_to_ledger(txn_time: Optional[int]) -> dict:
nonlocal node
req = sdk_random_request_objects(1, CURRENT_PROTOCOL_VERSION, identifier='someidentifier')[0]
txn = reqToTxn(req)
node.domainLedger.append_txns_metadata([txn], txn_time=txn_time)
node.domainLedger.appendTxns([txn])
return txn

# Process some genesis txn (which doesn't have timestamp)
genesis_txn = add_txn_to_ledger(txn_time=None)
node.postTxnFromCatchupAddedToLedger(DOMAIN_LEDGER_ID, genesis_txn)

# Process some other txn (which does have timestamp)
other_txn = add_txn_to_ledger(txn_time=13439852)
node.postTxnFromCatchupAddedToLedger(DOMAIN_LEDGER_ID, other_txn)