@@ -560,6 +560,10 @@ void Schain::blockCommitArrived(block_id _committedBlockID, schain_index _propos
560560 if ( isBite2PatchEnabled ) {
561561 CHECK_ARGUMENT (_reencryptionThresholdSig)
562562 }
563+ else {
564+ // enforce bite2 blocks are rejected if we are not yet in bite2 patch
565+ CHECK_ARGUMENT (!_reencryptionThresholdSig)
566+ }
563567#endif
564568#endif
565569
@@ -950,13 +954,12 @@ void Schain::saveBlock(const ptr<CommittedBlock> &_block) {
950954
951955 try {
952956 checkForExit ();
953- // save in block db
954- getNode ()->getBlockDB ()->saveBlock (_block);
955957
956958#ifdef BITE2
959+ // save random before saving block. If block is ever available in db, random should also be
957960 // compute reencryption random from block signature & save in random db
958961 std::optional<string> reencryptionSignature = _block->getReencryptionThresholdSig ();
959- bool isBite2PatchEnabled = bite2Patch (_block-> getTimeStampS () );
962+ bool isBite2PatchEnabled = bite2Patch ( getLastCommittedBlockTimeStamp (). getS () );
960963 if (isBite2PatchEnabled) {
961964 CHECK_STATE2 (reencryptionSignature.has_value (),
962965 " BITE2 patch is enabled but reencryption signature is missing for block " + to_string ( _block->getBlockID () ));
@@ -967,7 +970,15 @@ void Schain::saveBlock(const ptr<CommittedBlock> &_block) {
967970 getSchain ()->getNode ()->getRandomDB ()->writeDomainRandom (
968971 blockconsensus::REENCRYPTION_RANDOM_DOMAIN , _block->getBlockID (), random );
969972 }
973+ else {
974+ CHECK_STATE2 (!reencryptionSignature.has_value (),
975+ " BITE2 patch is not enabled but reencryption signature is present for block " + to_string ( _block->getBlockID () ));
976+ }
970977#endif
978+
979+ // save in block db
980+ getNode ()->getBlockDB ()->saveBlock (_block);
981+
971982 } catch (ExitRequestedException &) {
972983 throw ;
973984 } catch (...) {
@@ -1233,12 +1244,18 @@ void Schain::bootstrap(block_id _lastCommittedBlockID, uint64_t _lastCommittedBl
12331244 }
12341245
12351246
1236- // Step 0 Workaround for the fact that skaled does not yet save timestampMs
1237-
1238- if (_lastCommittedBlockTimeStampMs == 0 && _lastCommittedBlockID > 0 ) {
1247+ // Step 0: recover missing timestamp fields from consensus DB block if needed.
1248+ // For test/continue startup we may only know the last committed block id.
1249+ if ( _lastCommittedBlockID > 0 &&
1250+ ( _lastCommittedBlockTimeStamp == 0 || _lastCommittedBlockTimeStampMs == 0 ) ) {
12391251 auto block = getNode ()->getBlockDB ()->getBlock (_lastCommittedBlockID, getCryptoManager ());
12401252 if (block) {
1241- _lastCommittedBlockTimeStampMs = block->getTimeStampMs ();
1253+ if ( _lastCommittedBlockTimeStamp == 0 ) {
1254+ _lastCommittedBlockTimeStamp = block->getTimeStampS ();
1255+ }
1256+ if ( _lastCommittedBlockTimeStampMs == 0 ) {
1257+ _lastCommittedBlockTimeStampMs = block->getTimeStampMs ();
1258+ }
12421259 };
12431260 }
12441261
@@ -1262,12 +1279,16 @@ void Schain::bootstrap(block_id _lastCommittedBlockID, uint64_t _lastCommittedBl
12621279 while (lastCommittedBlockIDInConsensus > _lastCommittedBlockID)
12631280
12641281 try {
1282+ bool isBite2PatchEnabledForBlock = false ;
1283+ #ifdef BITE2
1284+ isBite2PatchEnabledForBlock = bite2Patch ( getLastCommittedBlockTimeStamp ().getS () );
1285+ #endif
12651286 auto block = getNode ()->getBlockDB ()->getBlock (
1266- _lastCommittedBlockID + 1 , getCryptoManager ());
1287+ _lastCommittedBlockID + 1 , getCryptoManager () );
12671288 CHECK_STATE2 (block, " No block in consensus, repair needed" );
12681289#ifdef BITE2
1269- if ( bite2Patch ( block->getTimeStampS () ) ) {
1270- auto reencryptionSignature = block-> getReencryptionThresholdSig ();
1290+ auto reencryptionSignature = block->getReencryptionThresholdSig ();
1291+ if ( isBite2PatchEnabledForBlock ) {
12711292 CHECK_STATE2 ( reencryptionSignature.has_value (),
12721293 " BITE2 patch is enabled but reencryption signature is missing for replayed block " +
12731294 to_string ( (uint64_t ) block->getBlockID () ) );
@@ -1279,6 +1300,11 @@ void Schain::bootstrap(block_id _lastCommittedBlockID, uint64_t _lastCommittedBl
12791300 getNode ()->getRandomDB ()->writeDomainRandom (
12801301 blockconsensus::REENCRYPTION_RANDOM_DOMAIN , block->getBlockID (), random );
12811302 }
1303+ else {
1304+ CHECK_STATE2 ( !reencryptionSignature.has_value (),
1305+ " BITE2 patch is not enabled but reencryption signature is present for replayed block " +
1306+ to_string ( (uint64_t ) block->getBlockID () ) );
1307+ }
12821308#endif
12831309 pushBlockToExtFace (block);
12841310 _lastCommittedBlockID = _lastCommittedBlockID + 1 ;
@@ -1650,8 +1676,12 @@ void Schain::finalizeDecidedAndSignedBlockInThread(block_id _blockId, schain_ind
16501676 CHECK_STATE (keys);
16511677
16521678 auto transactions = proposal->getTransactionList ();
1679+ bool isBite2PatchEnabledForBlock = false ;
1680+ #ifdef BITE2
1681+ isBite2PatchEnabledForBlock = bite2Patch ( getLastCommittedBlockTimeStamp ().getS () );
1682+ #endif
16531683 auto decryptedTransactions = getBiteManager ()->verifyAndDecryptTransactionList (
1654- *transactions, (*keys), proposal->getEpochID (), proposal-> getTimeStampS () );
1684+ *transactions, (*keys), ( uint64_t ) proposal->getEpochID (), isBite2PatchEnabledForBlock );
16551685#endif
16561686
16571687 auto daProofSig = getNode ()->getDaProofDB ()->getDASig ( _blockId, _proposerIndex );
0 commit comments