Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eip7251: Set MAX=2 for consolidations contract #37

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/consolidations/main.eas
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#define MIN_FEE = 1
#define TARGET_PER_BLOCK = 1
#define MAX_PER_BLOCK = 1
#define MAX_PER_BLOCK = 2
#define FEE_UPDATE_FRACTION = 17
#define EXCESS_INHIBITOR = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

Expand Down
37 changes: 20 additions & 17 deletions test/Consolidation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "geas-ffi/Geas.sol";
import "./Test.sol";

uint256 constant target_per_block = 1;
uint256 constant max_per_block = 1;
uint256 constant max_per_block = 2;
uint256 constant inhibitor = uint256(bytes32(0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff));

contract ConsolidationTest is Test {
Expand Down Expand Up @@ -63,7 +63,7 @@ contract ConsolidationTest is Test {
// request than can be read per block, the queue is eventually cleared and the
// head and tails are reset to zero.
function testQueueReset() public {
// Add more requests than the max per block (1) so that the queue is not
// Add more requests than the max per block (2) so that the queue is not
// immediately emptied.
for (uint256 i = 0; i < max_per_block+1; i++) {
addRequest(address(uint160(i)), makeConsolidation(i), 2);
Expand All @@ -72,36 +72,36 @@ contract ConsolidationTest is Test {

// Simulate syscall, check that max requests per block are read.
checkConsolidations(0, max_per_block);
assertExcess(1);
assertExcess(2);

// Add another batch of max requests per block (1) so the next read leaves a
// Add another batch of max requests per block (2) so the next read leaves a
// single request in the queue.
for (uint256 i = 2; i < 3; i++) {
for (uint256 i = 3; i < 3 + max_per_block; i++) {
addRequest(address(uint160(i)), makeConsolidation(i), 2);
}
assertStorage(count_slot, max_per_block, "unexpected request count");

// Simulate syscall. Verify first that max per block are read. Then
// verify only the single final requst is read.
checkConsolidations(1, max_per_block);
assertExcess(1);
checkConsolidations(2, 1);
assertExcess(0);
// verify only the single final request is read.
checkConsolidations(2, max_per_block);
assertExcess(3);
checkConsolidations(4, 1);
assertExcess(2);

// Now ensure the queue is empty and has reset to zero.
assertStorage(queue_head_slot, 0, "expected queue head reset");
assertStorage(queue_tail_slot, 0, "expected queue tail reset");

// Add five (5) more requests to check that new requests can be added after the queue
// is reset.
for (uint256 i = 3; i < 8; i++) {
for (uint256 i = 5; i < 10; i++) {
addRequest(address(uint160(i)), makeConsolidation(i), 4);
}
assertStorage(count_slot, 5, "unexpected request count");

// Simulate syscall, read only the max requests per block.
checkConsolidations(3, 1);
assertExcess(4);
checkConsolidations(5, max_per_block);
assertExcess(6);
}

// testFee adds many requests, and verifies the fee decreases correctly until
Expand All @@ -127,20 +127,23 @@ contract ConsolidationTest is Test {
assertExcess(excess);

uint256 fee = computeFee(excess);
if (idx % 2 == 0) {
bool success = (i % 2 == 0);
if (success) {
addRequest(address(uint160(idx)), makeConsolidation(idx), fee);
// Bump index when a new request is created
idx++;
} else {
addFailedRequest(address(uint160(idx)), makeConsolidation(idx), fee-1);
}

uint256 expected = min(idx-read+1, max_per_block);
uint256 queue_size = idx - read;
uint256 expected = min(queue_size, max_per_block);
checkConsolidations(read, expected);

if (excess > 0 && idx % 2 != 0) {
if (excess > 0 && !success) {
excess--;
}
read += expected;
idx++;
}

}
Expand Down
Loading