Skip to content

Commit

Permalink
Merge pull request #25 from ethstorage/emptymine
Browse files Browse the repository at this point in the history
Support mining empty shards
  • Loading branch information
syntrust authored Sep 22, 2023
2 parents 6c55e83 + 51a0d5f commit 88a5df8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions contracts/EthStorageContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ contract EthStorageContract is StorageContract, Decoder {
uint256 decodedData,
bytes memory peInput
) public view returns (bool) {
if (dataHash == 0x0) {
return decodedData == 0;
}
// peInput includes an input point that comes from bit reversed sampleIdxInKv
uint256 sampleIdxInKvRev = BinaryRelated.reverseBits(12, sampleIdxInKv);
uint256 xBls = modExp(ruBls, sampleIdxInKvRev, modulusBls);
Expand Down
9 changes: 7 additions & 2 deletions contracts/StorageContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ abstract contract StorageContract is DecentralizedKV {
treasury = _treasury;
prepaidAmount = _prepaidAmount;
prepaidLastMineTime = _startTime;
// make sure shard0 is ready to mine and pay correctly
infos[0].lastMineTime = _startTime;
}

event MinedBlock(
Expand All @@ -81,7 +83,10 @@ abstract contract StorageContract is DecentralizedKV {
// Open a new shard if the KV is the first one of the shard
// and mark the shard is ready to mine.
// (TODO): Setup shard difficulty as current difficulty / factor?
infos[shardId].lastMineTime = timestamp;
if (shardId != 0) {
// shard0 is already opened in constructor
infos[shardId].lastMineTime = timestamp;
}
}

require(msg.value >= _upfrontPayment(infos[shardId].lastMineTime), "not enough payment");
Expand Down Expand Up @@ -164,7 +169,7 @@ abstract contract StorageContract is DecentralizedKV {
// Mining is successful.
// Send reward to coinbase and miner.
MiningLib.MiningInfo storage info = infos[shardId];
uint256 lastShardIdx = (lastKvIdx - 1) >> shardEntryBits;
uint256 lastShardIdx = lastKvIdx > 0 ? (lastKvIdx - 1) >> shardEntryBits : 0;
uint256 reward = 0;
if (shardId < lastShardIdx) {
reward = _paymentIn(storageCost << shardEntryBits, info.lastMineTime, minedTs);
Expand Down

0 comments on commit 88a5df8

Please sign in to comment.