Skip to content

Commit

Permalink
Ban claim_stake_reward6 in stage txpool
Browse files Browse the repository at this point in the history
  • Loading branch information
moreal committed Aug 22, 2023
1 parent 69b958e commit 847ab9a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .Lib9c.Tests/StagePolicyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace Lib9c.Tests
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Bencodex.Types;
using Lib9c.Tests.TestHelper;
using Libplanet.Action;
using Libplanet.Blockchain;
Expand Down Expand Up @@ -228,6 +229,43 @@ public void CalculateNextTxNonceCorrectWhenTxOverQuota()
txB);
}

[Fact]
public void Stage_BanActionTypeId()
{
NCStagePolicy stagePolicy = new NCStagePolicy(TimeSpan.FromHours(1), 2);
BlockChain chain = MakeChainWithStagePolicy(stagePolicy);

var claimStakeReward = new ClaimStakeReward(default).PlainValue;
Assert.Equal(
(Text)"claim_stake_reward6",
Assert.IsType<Dictionary>(claimStakeReward)["type_id"]);
Assert.False(stagePolicy.Stage(
chain,
Transaction.Create(
0,
_accounts[0],
default,
new[] { claimStakeReward }
)
));

Assert.True(stagePolicy.Stage(
chain,
Transaction.Create(
0,
_accounts[0],
default,
new[]
{
new DailyReward()
{
avatarAddress = default,
},
}.ToPlainValues()
)
));
}

private void AssertTxs(BlockChain blockChain, NCStagePolicy policy, params Transaction[] txs)
{
foreach (Transaction tx in txs)
Expand Down
15 changes: 15 additions & 0 deletions Lib9c.Policy/NCStagePolicy.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Bencodex.Types;

namespace Nekoyume.Blockchain
{
using System;
Expand Down Expand Up @@ -39,6 +41,11 @@ public class NCStagePolicy : IStagePolicy
new Address("CAFC88175f88973d01e6A9479b31eC0beb020b8a"),
}.ToImmutableHashSet();

private static readonly ImmutableHashSet<string> _bannedActionTypeIds = new[]
{
"claim_stake_reward6",
}.ToImmutableHashSet();

public NCStagePolicy(TimeSpan txLifeTime, int quotaPerSigner)
{
if (quotaPerSigner < 1)
Expand Down Expand Up @@ -102,6 +109,14 @@ public bool Stage(BlockChain blockChain, Transaction transaction)
return false;
}

if (transaction.Actions.Count == 1 &&
transaction.Actions[0] is Dictionary dictionary &&
dictionary.TryGetValue((Text)"type_id", out var typeIdValue) &&
typeIdValue is Text typeId && _bannedActionTypeIds.Contains(typeId.Value))
{
return false;
}

var deniedTxs = new[]
{
// CreatePledge Transaction with 50000 addresses
Expand Down

0 comments on commit 847ab9a

Please sign in to comment.