Skip to content

Commit

Permalink
reduce rate limiter amount to 1M per 12 hours
Browse files Browse the repository at this point in the history
  • Loading branch information
darcys22 committed Aug 30, 2024
1 parent 61f494f commit e37d7ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions contracts/ServiceNodeRewards.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ contract ServiceNodeRewards is Initializable, Ownable2StepUpgradeable, PausableU
uint256 public blsNonSignerThreshold;
uint256 public blsNonSignerThresholdMax;
uint256 public claimThreshold;
uint256 public claimCycle;
uint256 public periodicClaims;
uint256 public epochDay;

This comment has been minimized.

Copy link
@jagerman

jagerman Aug 30, 2024

Member

Perhaps rename to something like epochNum now since it's no longer a day?

uint256 public signatureExpiry;
Expand Down Expand Up @@ -78,7 +79,8 @@ contract ServiceNodeRewards is Initializable, Ownable2StepUpgradeable, PausableU
liquidateTag = buildTag("BLS_SIG_TRYANDINCREMENT_LIQUIDATE");
hashToG2Tag = buildTag("BLS_SIG_HASH_TO_FIELD_TAG");
signatureExpiry = 10 minutes;
claimThreshold = 2_000_000 * 1e9;
claimThreshold = 1_000_000 * 1e9;
claimCycle = 12 hours;
periodicClaims = 0;
epochDay = 0;

Expand Down Expand Up @@ -248,7 +250,7 @@ contract ServiceNodeRewards is Initializable, Ownable2StepUpgradeable, PausableU
if (amount > maxAmount)
revert MaxClaimExceeded();

uint256 _epochDay = block.timestamp / 86400;
uint256 _epochDay = block.timestamp / claimCycle;
if (_epochDay > epochDay) {
epochDay = _epochDay;
periodicClaims = 0;
Expand Down
12 changes: 6 additions & 6 deletions test/cpp/test/src/rewards_contract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ TEST_CASE( "Rewards Contract", "[ethereum]" ) {
resetContractToSnapshot();
}

SECTION( "Claim too much rewards over two transactions and trigger rate limiter" ) {
SECTION( "Claim too much rewards but over the waiting time should succeed" ) {
REQUIRE(rewards_contract.serviceNodesLength() == 0);
ServiceNodeList snl(3);
for(auto& node : snl.nodes) {
Expand All @@ -648,7 +648,7 @@ TEST_CASE( "Rewards Contract", "[ethereum]" ) {
REQUIRE(rewards_contract.serviceNodesLength() == 3);
std::vector<unsigned char> secondseckey = ethyl::utils::fromHexString(std::string(config.ADDITIONAL_PRIVATE_KEY1));
const std::string recipientAddress = signer.secretKeyToAddressString(secondseckey);
const uint64_t recipientAmount = 1500000000000000;
const uint64_t recipientAmount = 500000000000000;
const auto signers = snl.randomSigners(snl.nodes.size());
const auto sig = snl.updateRewardsBalance(recipientAddress, recipientAmount, config.CHAIN_ID, contract_address, signers);
const auto non_signers = snl.findNonSigners(signers);
Expand All @@ -657,7 +657,7 @@ TEST_CASE( "Rewards Contract", "[ethereum]" ) {
uint64_t amount = erc20_contract.balanceOf(recipientAddress);
REQUIRE(amount == 0);

const uint64_t secondRecipientAmount = 3000000000000000;
const uint64_t secondRecipientAmount = 1100000000000000;
tx = erc20_contract.transfer(contract_address, secondRecipientAmount);
hash = signer.sendTransaction(tx, seckey);
REQUIRE(hash != "");
Expand Down Expand Up @@ -687,7 +687,7 @@ TEST_CASE( "Rewards Contract", "[ethereum]" ) {
resetContractToSnapshot();
}

SECTION( "Claim too much rewards but over the waiting time should succeed" ) {
SECTION( "Claim too much rewards over two transactions and trigger rate limiter" ) {
REQUIRE(rewards_contract.serviceNodesLength() == 0);
ServiceNodeList snl(3);
for(auto& node : snl.nodes) {
Expand All @@ -699,7 +699,7 @@ TEST_CASE( "Rewards Contract", "[ethereum]" ) {
REQUIRE(rewards_contract.serviceNodesLength() == 3);
std::vector<unsigned char> secondseckey = ethyl::utils::fromHexString(std::string(config.ADDITIONAL_PRIVATE_KEY1));
const std::string recipientAddress = signer.secretKeyToAddressString(secondseckey);
const uint64_t recipientAmount = 1500000000000000;
const uint64_t recipientAmount = 500000000000000;
const auto signers = snl.randomSigners(snl.nodes.size());
const auto sig = snl.updateRewardsBalance(recipientAddress, recipientAmount, config.CHAIN_ID, contract_address, signers);
const auto non_signers = snl.findNonSigners(signers);
Expand All @@ -708,7 +708,7 @@ TEST_CASE( "Rewards Contract", "[ethereum]" ) {
uint64_t amount = erc20_contract.balanceOf(recipientAddress);
REQUIRE(amount == 0);

const uint64_t secondRecipientAmount = 3000000000000000;
const uint64_t secondRecipientAmount = 1100000000000000;
tx = erc20_contract.transfer(contract_address, secondRecipientAmount);
hash = signer.sendTransaction(tx, seckey);
REQUIRE(hash != "");
Expand Down

0 comments on commit e37d7ee

Please sign in to comment.