add batch size check in rollup contract
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 44s
Details
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 44s
Details
This commit is contained in:
parent
08dee20a29
commit
9702626e0e
|
@ -8,10 +8,10 @@ contract Rollup is Availability {
|
|||
constructor(DAO dao) Availability(dao) {}
|
||||
|
||||
struct BatchItem {
|
||||
address worker;
|
||||
address author;
|
||||
uint stakeAmount;
|
||||
uint fee;
|
||||
string evidenceContentId;
|
||||
string postId;
|
||||
}
|
||||
|
||||
mapping(uint => BatchItem) items;
|
||||
|
@ -19,22 +19,29 @@ contract Rollup is Availability {
|
|||
address batchWorker;
|
||||
uint batchWorkerStakeIndex;
|
||||
|
||||
/// Instead of initiating a validation pool, call this method to include
|
||||
/// the stakes and fee in the next batch validation pool
|
||||
function addItem(
|
||||
address worker,
|
||||
address author,
|
||||
uint stakeAmount,
|
||||
string calldata evidenceContentId
|
||||
string calldata postId
|
||||
) public payable {
|
||||
BatchItem storage item = items[itemCount++];
|
||||
item.worker = worker;
|
||||
item.author = author;
|
||||
item.stakeAmount = stakeAmount;
|
||||
item.fee = msg.value;
|
||||
item.evidenceContentId = evidenceContentId;
|
||||
item.postId = postId;
|
||||
}
|
||||
|
||||
/// To be called by the currently assigned batch worker,
|
||||
/// If no batch worker has been assigned this may be called by anybody,
|
||||
/// but it will only succeed if it is able to assign a new worker.
|
||||
function submitBatch(
|
||||
string calldata batchPostId,
|
||||
uint batchSize,
|
||||
uint poolDuration
|
||||
) public {
|
||||
) public returns (uint poolIndex) {
|
||||
require(batchSize <= itemCount, "Batch size too large");
|
||||
if (batchWorker != address(0)) {
|
||||
require(
|
||||
msg.sender == batchWorker,
|
||||
|
@ -46,7 +53,7 @@ contract Rollup is Availability {
|
|||
for (uint i = 0; i < itemCount; i++) {
|
||||
fee += items[i].fee;
|
||||
}
|
||||
uint poolIndex = dao.initiateValidationPool{value: fee}(
|
||||
poolIndex = dao.initiateValidationPool{value: fee}(
|
||||
batchPostId,
|
||||
poolDuration,
|
||||
[uint256(1), uint256(3)],
|
||||
|
@ -60,20 +67,31 @@ contract Rollup is Availability {
|
|||
for (uint i = 0; i < itemCount; i++) {
|
||||
dao.delegatedStakeOnValidationPool(
|
||||
poolIndex,
|
||||
items[i].worker,
|
||||
items[i].author,
|
||||
items[i].stakeAmount,
|
||||
true
|
||||
);
|
||||
}
|
||||
// Include availability stakes from the batch worker
|
||||
dao.delegatedStakeOnValidationPool(
|
||||
poolIndex,
|
||||
batchWorker,
|
||||
stakes[batchWorkerStakeIndex].amount,
|
||||
true
|
||||
);
|
||||
// Reset item count so we can start the next batch
|
||||
itemCount = 0;
|
||||
if (batchWorker != address(0)) {
|
||||
dao.delegatedStakeOnValidationPool(
|
||||
poolIndex,
|
||||
batchWorker,
|
||||
stakes[batchWorkerStakeIndex].amount,
|
||||
true
|
||||
);
|
||||
}
|
||||
if (batchSize < itemCount) {
|
||||
// Some items were added after this batch was computed.
|
||||
// Keep them in the queue to be included in the next batch.
|
||||
for (uint i = 0; i < itemCount - batchSize; i++) {
|
||||
items[i] = items[batchSize + i];
|
||||
}
|
||||
itemCount = itemCount - batchSize;
|
||||
} else {
|
||||
// Reset item count so we can start the next batch
|
||||
itemCount = 0;
|
||||
}
|
||||
// Select the next worker
|
||||
batchWorkerStakeIndex = assignWork();
|
||||
batchWorker = stakes[batchWorkerStakeIndex].worker;
|
||||
|
|
Loading…
Reference in New Issue