mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 07:58:22 -05:00
sharding: fixed notary sample function
Former-commit-id: 608025faad454e517fd144759886e04113805907 [formerly 5b753cdef5fc3f4f4f585e972ba624a42d21c672] Former-commit-id: 8125d538d91209971860ed637b456ff07dff8151
This commit is contained in:
@@ -72,7 +72,7 @@ contract SMC {
|
||||
// Log the latest period number of the shard
|
||||
mapping (int => int) public periodHead;
|
||||
|
||||
/// Checks if a notary with given shard id and period has been chosen as
|
||||
/// Checks if a notary with given shard id and period has been chosen as
|
||||
/// a committee member to vote for header added on to the main chain
|
||||
function isNotaryInCommittee(uint shardId, uint period) public view returns(bool) {
|
||||
uint currentPeriod = block.number / PERIOD_LENGTH;
|
||||
@@ -94,7 +94,7 @@ contract SMC {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Registers notary to notatery registry, locks in the notary deposit,
|
||||
@@ -106,11 +106,11 @@ contract SMC {
|
||||
|
||||
// Track the numbers of participating notaries in between periods
|
||||
updateNotarySampleSize();
|
||||
|
||||
|
||||
uint index;
|
||||
if (emptyStack()) {
|
||||
index = notaryPoolLength;
|
||||
notaryPool.push(notaryAddress);
|
||||
index = notaryPoolLength;
|
||||
notaryPool.push(notaryAddress);
|
||||
} else {
|
||||
index = stackPop();
|
||||
notaryPool[index] = notaryAddress;
|
||||
@@ -127,7 +127,7 @@ contract SMC {
|
||||
if (index >= nextPeriodNotarySampleSize) {
|
||||
nextPeriodNotarySampleSize = index + 1;
|
||||
}
|
||||
|
||||
|
||||
emit NotaryRegistered(notaryAddress, index);
|
||||
return true;
|
||||
}
|
||||
@@ -143,7 +143,7 @@ contract SMC {
|
||||
|
||||
// Track the numbers of participating notaries in between periods
|
||||
updateNotarySampleSize();
|
||||
|
||||
|
||||
uint deregisteredPeriod = block.number / PERIOD_LENGTH;
|
||||
notaryRegistry[notaryAddress].deregisteredPeriod = deregisteredPeriod;
|
||||
|
||||
@@ -171,7 +171,7 @@ contract SMC {
|
||||
/// Calcuates the hash of the header from the input parameters
|
||||
function computeHeaderHash(
|
||||
uint256 shardId,
|
||||
bytes32 parentHash,
|
||||
bytes32 parentHash,
|
||||
bytes32 chunkRoot,
|
||||
uint256 period,
|
||||
address proposerAddress
|
||||
@@ -185,7 +185,7 @@ contract SMC {
|
||||
function addHeader(
|
||||
uint _shardId,
|
||||
uint period,
|
||||
bytes32 chunkRoot,
|
||||
bytes32 chunkRoot,
|
||||
address proposerAddress
|
||||
) public returns(bool) {
|
||||
/*
|
||||
@@ -199,8 +199,9 @@ contract SMC {
|
||||
/// before notary registration/deregistration so correct size can be applied next period
|
||||
function updateNotarySampleSize() internal returns(bool) {
|
||||
uint currentPeriod = block.number / PERIOD_LENGTH;
|
||||
require(currentPeriod < sampleSizeLastUpdatedPeriod);
|
||||
|
||||
if (currentPeriod < sampleSizeLastUpdatedPeriod) {
|
||||
return false;
|
||||
}
|
||||
currentPeriodNotarySampleSize = nextPeriodNotarySampleSize;
|
||||
sampleSizeLastUpdatedPeriod = currentPeriod;
|
||||
return true;
|
||||
@@ -226,5 +227,5 @@ contract SMC {
|
||||
require(emptySlotsStackTop > 1);
|
||||
--emptySlotsStackTop;
|
||||
return emptySlotsStack[emptySlotsStackTop];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user