Skip to content

Commit e913b00

Browse files
committed
#1003 fix & improve consensus tests
1 parent 87cceda commit e913b00

5 files changed

Lines changed: 96 additions & 31 deletions

File tree

bite/BiteManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void BiteManager::parseBITETransactions(
5757
.currentEpoch = _proposal->getEpochID()
5858
#ifdef BITE2
5959
,
60-
.isBite2PatchEnabled = schain.bite2Patch( schain.getLastCommittedBlockTimeStamp().getS() )
60+
.isBite2PatchEnabled = schain.bite2Patch( _proposal->getTimeStampS() )
6161
#endif
6262
};
6363

headers/CommittedBlockHeader.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ CommittedBlockHeader::CommittedBlockHeader( CommittedBlock& _block )
4545

4646
#ifdef BITE2
4747
// should only be present in the block after bite2 patch timestamp
48-
reencryptionThresholdSig = Header::maybeGetString( _json, "reencryptionThrSig" );
48+
auto maybeReencryptionThresholdSig = Header::maybeGetString( _json, "reencryptionThrSig" );
49+
reencryptionThresholdSig = maybeReencryptionThresholdSig.empty()
50+
? std::nullopt
51+
: std::optional<string>( maybeReencryptionThresholdSig );
4952
#endif
5053

5154
daSig = Header::maybeGetString( _json, "daSig" );

tests/e2e/E2ETestHelper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class E2ETestHelper {
7070
uint64_t _runTimeS,
7171
const std::map< string, uint64_t >& _patchTimestamps = { // default patch timestamps
7272
#ifdef BITE2
73-
{ "bite2PatchTimestamp", 1 }
73+
{ "bite2PatchTimestamp", 0 }
7474
#endif
7575
} ) {
7676
_engine = new ConsensusEngine( _lastId, 1000000000 );

tests/e2e/bite/ReencryptionRandomConsensusTests.cpp

Lines changed: 89 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
@date 2026
2121
*/
2222

23+
#include <cstdint>
2324
#ifdef BITE2
2425

2526
#include "thirdparty/catch.hpp"
@@ -72,6 +73,77 @@ std::map< uint64_t, u256 > readReencryptionRandoms(
7273

7374
using namespace RandomTests;
7475

76+
77+
CATCH_TEST_CASE(
78+
"normal consensus prior to bite2 patch timestamp with default blocks",
79+
"[pre-patch][end-to-end][db][bite2]" ) {
80+
81+
ConsensusEngine* testEngine = nullptr;
82+
83+
try {
84+
E2EHelper::configureTestEnvironment( true, "test/twonodes_sameip" );
85+
auto runTimeS = E2EHelper::CROSS_NODE_RUN_TIME_S;
86+
auto lastId =
87+
( uint64_t ) E2EHelper::startEngineAndWait( testEngine, 0, runTimeS );
88+
89+
// Two-node setup can need extra time before first DB commit; poll briefly before failing.
90+
for ( int i = 0; i < 70 && lastId == 0; i++ ) {
91+
usleep( 500 * 1000 );
92+
lastId = ( uint64_t ) testEngine->getLargestCommittedBlockIDInDb();
93+
}
94+
95+
CATCH_REQUIRE( lastId > 0 );
96+
CATCH_REQUIRE( ( uint64_t ) testEngine->nodesCount() == 2 );
97+
98+
auto nodeIds = testEngine->getNodeIDs();
99+
CATCH_REQUIRE( nodeIds.size() == 2 );
100+
101+
auto nodeIt = nodeIds.begin();
102+
auto firstNodeId = *nodeIt;
103+
++nodeIt;
104+
auto secondNodeId = *nodeIt;
105+
106+
uint32_t exceptionsNode1 = 0;
107+
uint32_t exceptionsNode2 = 0;
108+
109+
// no reencryption random should be present for any block
110+
// Calls SHOULD throw until patch timestamp (meaning they are not usable)
111+
for ( uint64_t blockId = 1; blockId <= lastId; blockId++ ) {
112+
try {
113+
testEngine->getReencryptionRandomForBlockIdForNode( blockId, firstNodeId );
114+
} catch ( ... ) {
115+
exceptionsNode1++;
116+
}
117+
118+
try {
119+
testEngine->getReencryptionRandomForBlockIdForNode( blockId, secondNodeId );
120+
} catch ( ... ) {
121+
exceptionsNode2++;
122+
}
123+
}
124+
125+
CATCH_REQUIRE( exceptionsNode1 > 0 );
126+
CATCH_REQUIRE( exceptionsNode2 > 0 );
127+
CATCH_REQUIRE( exceptionsNode1 == exceptionsNode2 );
128+
129+
E2EHelper::stopEngineGracefully( testEngine );
130+
} catch ( SkaleException& e ) {
131+
if ( testEngine ) {
132+
E2EHelper::stopEngineGracefully( testEngine );
133+
}
134+
SkaleException::logNested( e );
135+
throw;
136+
} catch ( ... ) {
137+
if ( testEngine ) {
138+
E2EHelper::stopEngineGracefully( testEngine );
139+
}
140+
throw;
141+
}
142+
143+
CATCH_SUCCEED();
144+
}
145+
146+
75147
CATCH_TEST_CASE(
76148
"reencryption random is equal across nodes for same block ids",
77149
"[reencryption-random-cross-node][end-to-end][db][bite2]" ) {
@@ -82,18 +154,15 @@ CATCH_TEST_CASE(
82154
E2EHelper::configureTestEnvironment( true, "test/twonodes_sameip" );
83155
auto runTimeS = E2EHelper::CROSS_NODE_RUN_TIME_S;
84156
auto lastId =
85-
( uint64_t ) E2EHelper::startEngineAndWait( testEngine, 0, runTimeS );
86-
auto lastIdInMemory = ( uint64_t ) testEngine->getLargestCommittedBlockID();
157+
( uint64_t ) E2EHelper::startEngineAndWait( testEngine, 0, runTimeS,
158+
{ { "bite2PatchTimestamp", 1 } } );
87159

88160
// Two-node setup can need extra time before first DB commit; poll briefly before failing.
89161
for ( int i = 0; i < 70 && lastId == 0; i++ ) {
90162
usleep( 500 * 1000 );
91163
lastId = ( uint64_t ) testEngine->getLargestCommittedBlockIDInDb();
92-
lastIdInMemory = ( uint64_t ) testEngine->getLargestCommittedBlockID();
93164
}
94165

95-
CATCH_INFO(
96-
"lastIdInDb=" << lastId << ", lastIdInMemory=" << lastIdInMemory << ", runTimeS=" << runTimeS );
97166
CATCH_REQUIRE( lastId > 0 );
98167
CATCH_REQUIRE( ( uint64_t ) testEngine->nodesCount() == 2 );
99168

@@ -154,11 +223,12 @@ CATCH_TEST_CASE(
154223
"[reencryption-random-committed][end-to-end][db][bite2]" ) {
155224

156225
ConsensusEngine* testEngine = nullptr;
157-
226+
158227
try {
159228
E2EHelper::configureTestEnvironment( true );
160229
// Start consensus and wait for blocks to be committed
161-
auto lastId = E2EHelper::startEngineAndWait( testEngine, 0, E2EHelper::DEFAULT_RUN_TIME_S );
230+
auto lastId = E2EHelper::startEngineAndWait( testEngine, 0, E2EHelper::DEFAULT_RUN_TIME_S,
231+
{ { "bite2PatchTimestamp", 1 } } );
162232

163233
CATCH_REQUIRE( lastId > 0 );
164234

@@ -199,11 +269,12 @@ CATCH_TEST_CASE(
199269
"[reencryption-random-deterministic][end-to-end][db][bite2]" ) {
200270

201271
ConsensusEngine* testEngine = nullptr;
202-
272+
203273
try {
204274
E2EHelper::configureTestEnvironment( true );
205275
// Start consensus and wait for blocks to be committed
206-
auto lastId = E2EHelper::startEngineAndWait( testEngine, 0, E2EHelper::DEFAULT_RUN_TIME_S );
276+
auto lastId = E2EHelper::startEngineAndWait( testEngine, 0, E2EHelper::DEFAULT_RUN_TIME_S,
277+
{ { "bite2PatchTimestamp", 1 } } );
207278

208279
CATCH_REQUIRE( lastId > 0 );
209280

@@ -245,17 +316,14 @@ CATCH_TEST_CASE(
245316
try {
246317
E2EHelper::configureTestEnvironment( true );
247318
// Start consensus and wait for blocks to be committed
248-
auto lastId = (uint64_t) E2EHelper::startEngineAndWait( testEngine, 0, E2EHelper::DEFAULT_RUN_TIME_S );
319+
auto lastId = (uint64_t) E2EHelper::startEngineAndWait( testEngine, 0, E2EHelper::DEFAULT_RUN_TIME_S,
320+
{ { "bite2PatchTimestamp", 1 } } );
249321

250322
CATCH_REQUIRE( lastId > 0 );
251323

252324
uint64_t checkedBlocks = 0;
253-
uint64_t startBlock = 1;
254-
#ifdef BITE2
255-
startBlock = 2;
256-
#endif
257325

258-
for ( uint64_t blockId = startBlock; blockId <= lastId; blockId++ ) {
326+
for ( uint64_t blockId = 1; blockId <= lastId; blockId++ ) {
259327
try {
260328
// For same committed block id, compare:
261329
// getReencryptionRandomForBlockId(id) vs getRandomForBlockId(id)
@@ -295,11 +363,12 @@ CATCH_TEST_CASE(
295363
"[reencryption-random-restart-1][end-to-end][db][bite2]" ) {
296364

297365
ConsensusEngine* testEngine = nullptr;
298-
366+
299367
try {
300368
E2EHelper::configureTestEnvironment( true );
301369
// First run: start from scratch and collect reencryption randoms
302-
auto lastId = (uint64_t) E2EHelper::startEngineAndWait( testEngine, 0, E2EHelper::DEFAULT_RUN_TIME_S );
370+
auto lastId = (uint64_t) E2EHelper::startEngineAndWait( testEngine, 0, E2EHelper::DEFAULT_RUN_TIME_S,
371+
{ { "bite2PatchTimestamp", 1 } } );
303372

304373
CATCH_REQUIRE( lastId > 0 );
305374

@@ -333,10 +402,10 @@ CATCH_TEST_CASE(
333402

334403
CATCH_TEST_CASE(
335404
"reencryption random survives restart - continue after restart",
336-
"[reencryption-random-restart-2][end-to-end][bite2]" ) {
405+
"[reencryption-random-restart-2][end-to-end][db][bite2]" ) {
337406

338407
ConsensusEngine* testEngine = nullptr;
339-
408+
340409
try {
341410
E2EHelper::configureTestEnvironment( false );
342411
// Load the randoms from before restart
@@ -359,6 +428,7 @@ CATCH_TEST_CASE(
359428

360429
// Restart with continue mode (_lastId == -1 path)
361430
testEngine = new ConsensusEngine( -1, 1000000000 );
431+
testEngine->setTestPatchTimestamps({ { "bite2PatchTimestamp", 1 } } );
362432
testEngine->parseTestConfigsAndCreateAllNodes( Consensust::getConfigDirPath(), true );
363433
testEngine->slowStartBootStrapTest();
364434

tests/e2e/bite/ReencryptionSignatureConsensusTest.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,10 @@ CATCH_TEST_CASE(
4747
"[reencryption-signature-transition][bite2][end-to-end][db]" ) {
4848

4949
ConsensusEngine* testEngine = nullptr;
50-
50+
5151
try {
5252
E2EHelper::configureTestEnvironment( true, "test/twonodes_sameip" );
5353

54-
auto snap = E2EHelper::setTestEnvVar("TEST_TRANSACTIONS_PER_BLOCK", "1");
55-
5654
uint64_t runTimeS = Consensust::getRunningTimeS();
5755
if ( runTimeS < 8 ) {
5856
runTimeS = 8;
@@ -114,10 +112,6 @@ CATCH_TEST_CASE(
114112
auto blockTimestamp = _block->getTimeStampS();
115113
auto reencryptionSignature = _block->getReencryptionThresholdSig();
116114

117-
CATCH_INFO( "blockId=" << blockId << ", nodeId=" << _nodeId <<
118-
", blockTimestamp=" << blockTimestamp <<
119-
", bite2PatchTimestamp=" << bite2PatchTimestamp );
120-
121115
if ( blockTimestamp < bite2PatchTimestamp ) {
122116
bool noReencryptionSignature =
123117
!reencryptionSignature.has_value() || reencryptionSignature->empty();
@@ -165,8 +159,6 @@ CATCH_TEST_CASE(
165159

166160
E2EHelper::stopEngineGracefully( testEngine );
167161

168-
E2EHelper::restoreTestEnvVar( "TEST_TRANSACTIONS_PER_BLOCK", snap );
169-
170162
} catch ( SkaleException& e ) {
171163
if ( testEngine ) {
172164
E2EHelper::stopEngineGracefully( testEngine );

0 commit comments

Comments
 (0)