Skip to content

Commit 60a49b4

Browse files
authored
Merge pull request #1187 from skhoroshavin/fix-ts-store
Fix crash when catching up genesis txns
2 parents 916368d + fb13b4f commit 60a49b4

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

plenum/server/node.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,8 +2179,9 @@ def postTxnFromCatchupAddedToLedger(self, ledger_id: int, txn: Any, updateSeqNo=
21792179
state = self.getState(ledger_id)
21802180
state.commit(rootHash=state.headHash)
21812181
if ledger_id == DOMAIN_LEDGER_ID and rh.ts_store:
2182-
rh.ts_store.set(get_txn_time(txn),
2183-
state.headHash)
2182+
timestamp = get_txn_time(txn)
2183+
if timestamp is not None:
2184+
rh.ts_store.set(timestamp, state.headHash)
21842185
logger.trace("{} added transaction with seqNo {} to ledger {} during catchup, state root {}"
21852186
.format(self, get_seq_no(txn), ledger_id,
21862187
state_roots_serializer.serialize(bytes(state.committedHeadHash))))
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from typing import Optional
2+
3+
from plenum.common.constants import DOMAIN_LEDGER_ID, CURRENT_PROTOCOL_VERSION
4+
from plenum.common.txn_util import reqToTxn
5+
from plenum.test.helper import sdk_random_request_objects
6+
7+
8+
def test_post_genesis_txn_from_catchup_added_to_ledger(looper, txnPoolNodeSet):
9+
node = txnPoolNodeSet[0]
10+
11+
def add_txn_to_ledger(txn_time: Optional[int]) -> dict:
12+
nonlocal node
13+
req = sdk_random_request_objects(1, CURRENT_PROTOCOL_VERSION, identifier='someidentifier')[0]
14+
txn = reqToTxn(req)
15+
node.domainLedger.append_txns_metadata([txn], txn_time=txn_time)
16+
node.domainLedger.appendTxns([txn])
17+
return txn
18+
19+
# Process some genesis txn (which doesn't have timestamp)
20+
genesis_txn = add_txn_to_ledger(txn_time=None)
21+
node.postTxnFromCatchupAddedToLedger(DOMAIN_LEDGER_ID, genesis_txn)
22+
23+
# Process some other txn (which does have timestamp)
24+
other_txn = add_txn_to_ledger(txn_time=13439852)
25+
node.postTxnFromCatchupAddedToLedger(DOMAIN_LEDGER_ID, other_txn)

0 commit comments

Comments
 (0)