Skip to content

Commit

Permalink
Merge pull request #2194 from planetarium/acs-tx-quota
Browse files Browse the repository at this point in the history
add GetTxQuota to ACS
  • Loading branch information
area363 authored Nov 2, 2023
2 parents dd343eb + 0648469 commit b77fc81
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Lib9c.Policy/AccessControlService/IAccessControlService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace Nekoyume.Blockchain
{
public interface IAccessControlService
{
public bool IsAccessDenied(Address address);
public int? GetTxQuota(Address address);
}
}
14 changes: 12 additions & 2 deletions Lib9c.Policy/NCStagePolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,16 @@ public IEnumerable<Transaction> Iterate(BlockChain blockChain, bool filtered = t
}

s.Add(tx);
if (s.Count > _quotaPerSigner)
int txQuotaPerSigner = _quotaPerSigner;

// update txQuotaPerSigner if ACS returns a value for the signer.
if (_accessControlService?.GetTxQuota(tx.Signer) is { } acsTxQuota)
{
txQuotaPerSigner = acsTxQuota;
}


if (s.Count > txQuotaPerSigner)
{
s.Remove(s.Max);
}
Expand All @@ -77,7 +86,8 @@ public IEnumerable<Transaction> Iterate(BlockChain blockChain, bool filtered = t

public bool Stage(BlockChain blockChain, Transaction transaction)
{
if (_accessControlService != null && _accessControlService.IsAccessDenied(transaction.Signer))
if (_accessControlService?.GetTxQuota(transaction.Signer) is { } acsTxQuota
&& acsTxQuota == 0)
{
return false;
}
Expand Down

0 comments on commit b77fc81

Please sign in to comment.