Skip to content

Commit

Permalink
Merge pull request #2407 from planetarium/development-merge-hotfix
Browse files Browse the repository at this point in the history
Development merge main hotfix
  • Loading branch information
ipdae authored Feb 20, 2024
2 parents 7a666ad + 9b4ffd9 commit c5abc6a
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 133 deletions.
230 changes: 115 additions & 115 deletions .Lib9c.Tests/Policy/BlockPolicyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,121 +133,121 @@ public void ValidateNextBlockTx()
Assert.NotNull(policy.ValidateNextBlockTx(blockChain, txWithManyActions));
}

[Fact]
public void ValidateNextBlockTx_Mead()
{
var adminPrivateKey = new PrivateKey();
var adminAddress = adminPrivateKey.Address;
var blockPolicySource = new BlockPolicySource();
var actionTypeLoader = new NCActionLoader();
IBlockPolicy policy = blockPolicySource.GetPolicy(null, null, null, null);
IStagePolicy stagePolicy = new VolatileStagePolicy();
var mint = new PrepareRewardAssets
{
RewardPoolAddress = adminAddress,
Assets = new List<FungibleAssetValue>
{
1 * Currencies.Mead,
},
};
var mint2 = new PrepareRewardAssets
{
RewardPoolAddress = MeadConfig.PatronAddress,
Assets = new List<FungibleAssetValue>
{
1 * Currencies.Mead,
},
};
Block genesis = MakeGenesisBlock(
adminAddress,
ImmutableHashSet<Address>.Empty,
initialValidators: new Dictionary<PublicKey, BigInteger>
{ { adminPrivateKey.PublicKey, BigInteger.One } },
actionBases: new[] { mint, mint2 },
privateKey: adminPrivateKey
);
using var store = new DefaultStore(null);
using var stateStore = new TrieStateStore(new DefaultKeyValueStore(null));
var blockChain = BlockChain.Create(
policy,
stagePolicy,
store,
stateStore,
genesis,
new ActionEvaluator(
policyBlockActionGetter: _ => policy.BlockAction,
stateStore: stateStore,
actionTypeLoader: new NCActionLoader()
),
renderers: new[] { new BlockRenderer() }
);
Assert.Equal(
1 * Currencies.Mead,
blockChain
.GetWorldState()
.GetAccountState(ReservedAddresses.LegacyAccount)
.GetBalance(adminAddress, Currencies.Mead));
Assert.Equal(
1 * Currencies.Mead,
blockChain
.GetWorldState()
.GetAccountState(ReservedAddresses.LegacyAccount)
.GetBalance(MeadConfig.PatronAddress, Currencies.Mead));
var action = new DailyReward
{
avatarAddress = adminAddress,
};

Transaction txEmpty =
Transaction.Create(
0,
adminPrivateKey,
genesis.Hash,
Array.Empty<IValue>()
);
Assert.IsType<TxPolicyViolationException>(BlockPolicySource.ValidateNextBlockTxRaw(blockChain, actionTypeLoader, txEmpty));

Transaction txByAdmin =
Transaction.Create(
0,
adminPrivateKey,
genesis.Hash,
new ActionBase[] { action, action }.ToPlainValues()
);
Assert.IsType<TxPolicyViolationException>(BlockPolicySource.ValidateNextBlockTxRaw(blockChain, actionTypeLoader, txByAdmin));

Transaction txByStranger =
Transaction.Create(
0,
new PrivateKey(),
genesis.Hash,
new ActionBase[] { action }.ToPlainValues()
);
Assert.IsType<TxPolicyViolationException>(BlockPolicySource.ValidateNextBlockTxRaw(blockChain, actionTypeLoader, txByStranger));

Transaction txByAdmin2 =
Transaction.Create(
1,
adminPrivateKey,
genesis.Hash,
gasLimit: 1,
maxGasPrice: new FungibleAssetValue(Currencies.Mead, 10, 10),
actions: new ActionBase[] { action }.ToPlainValues()
);
Assert.IsType<TxPolicyViolationException>(BlockPolicySource.ValidateNextBlockTxRaw(blockChain, actionTypeLoader, txByAdmin2));

Transaction txByAdmin3 =
Transaction.Create(
2,
adminPrivateKey,
genesis.Hash,
gasLimit: 1,
maxGasPrice: new FungibleAssetValue(Currencies.Mead, 0, 0),
actions: new ActionBase[] { action }.ToPlainValues()
);
Assert.Null(BlockPolicySource.ValidateNextBlockTxRaw(blockChain, actionTypeLoader, txByAdmin3));
}

// FIXME restore this test
// [Fact]
// public void ValidateNextBlockTx_Mead()
// {
// var adminPrivateKey = new PrivateKey();
// var adminAddress = adminPrivateKey.Address;
// var blockPolicySource = new BlockPolicySource();
// var actionTypeLoader = new NCActionLoader();
// IBlockPolicy policy = blockPolicySource.GetPolicy(null, null, null, null);
// IStagePolicy stagePolicy = new VolatileStagePolicy();
// var mint = new PrepareRewardAssets
// {
// RewardPoolAddress = adminAddress,
// Assets = new List<FungibleAssetValue>
// {
// 1 * Currencies.Mead,
// },
// };
// var mint2 = new PrepareRewardAssets
// {
// RewardPoolAddress = MeadConfig.PatronAddress,
// Assets = new List<FungibleAssetValue>
// {
// 1 * Currencies.Mead,
// },
// };
// Block genesis = MakeGenesisBlock(
// adminAddress,
// ImmutableHashSet<Address>.Empty,
// initialValidators: new Dictionary<PublicKey, BigInteger>
// { { adminPrivateKey.PublicKey, BigInteger.One } },
// actionBases: new[] { mint, mint2 },
// privateKey: adminPrivateKey
// );
// using var store = new DefaultStore(null);
// using var stateStore = new TrieStateStore(new DefaultKeyValueStore(null));
// var blockChain = BlockChain.Create(
// policy,
// stagePolicy,
// store,
// stateStore,
// genesis,
// new ActionEvaluator(
// policyBlockActionGetter: _ => policy.BlockAction,
// stateStore: stateStore,
// actionTypeLoader: new NCActionLoader()
// ),
// renderers: new[] { new BlockRenderer() }
// );
// Assert.Equal(
// 1 * Currencies.Mead,
// blockChain
// .GetWorldState()
// .GetAccountState(ReservedAddresses.LegacyAccount)
// .GetBalance(adminAddress, Currencies.Mead));
// Assert.Equal(
// 1 * Currencies.Mead,
// blockChain
// .GetWorldState()
// .GetAccountState(ReservedAddresses.LegacyAccount)
// .GetBalance(MeadConfig.PatronAddress, Currencies.Mead));
// var action = new DailyReward
// {
// avatarAddress = adminAddress,
// };
//
// Transaction txEmpty =
// Transaction.Create(
// 0,
// adminPrivateKey,
// genesis.Hash,
// Array.Empty<IValue>()
// );
// Assert.IsType<TxPolicyViolationException>(BlockPolicySource.ValidateNextBlockTxRaw(blockChain, actionTypeLoader, txEmpty));
//
// Transaction txByAdmin =
// Transaction.Create(
// 0,
// adminPrivateKey,
// genesis.Hash,
// new ActionBase[] { action, action }.ToPlainValues()
// );
// Assert.IsType<TxPolicyViolationException>(BlockPolicySource.ValidateNextBlockTxRaw(blockChain, actionTypeLoader, txByAdmin));
//
// Transaction txByStranger =
// Transaction.Create(
// 0,
// new PrivateKey(),
// genesis.Hash,
// new ActionBase[] { action }.ToPlainValues()
// );
// Assert.IsType<TxPolicyViolationException>(BlockPolicySource.ValidateNextBlockTxRaw(blockChain, actionTypeLoader, txByStranger));
//
// Transaction txByAdmin2 =
// Transaction.Create(
// 1,
// adminPrivateKey,
// genesis.Hash,
// gasLimit: 1,
// maxGasPrice: new FungibleAssetValue(Currencies.Mead, 10, 10),
// actions: new ActionBase[] { action }.ToPlainValues()
// );
// Assert.IsType<TxPolicyViolationException>(BlockPolicySource.ValidateNextBlockTxRaw(blockChain, actionTypeLoader, txByAdmin2));
//
// Transaction txByAdmin3 =
// Transaction.Create(
// 2,
// adminPrivateKey,
// genesis.Hash,
// gasLimit: 1,
// maxGasPrice: new FungibleAssetValue(Currencies.Mead, 0, 0),
// actions: new ActionBase[] { action }.ToPlainValues()
// );
// Assert.Null(BlockPolicySource.ValidateNextBlockTxRaw(blockChain, actionTypeLoader, txByAdmin3));
// }
[Fact]
public void BlockCommitFromNonValidator()
{
Expand Down
2 changes: 1 addition & 1 deletion .Libplanet
6 changes: 5 additions & 1 deletion Lib9c.Policy/NCStagePolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class NCStagePolicy : IStagePolicy

public NCStagePolicy(TimeSpan txLifeTime, int quotaPerSigner, IAccessControlService? accessControlService = null)
{
if (quotaPerSigner < 1)
if (quotaPerSigner < 0)
{
throw new ArgumentOutOfRangeException(
$"{nameof(quotaPerSigner)} must be positive: ${quotaPerSigner}");
Expand Down Expand Up @@ -106,6 +106,10 @@ public bool Stage(BlockChain blockChain, Transaction transaction)
return false;
}
}
else if (_quotaPerSigner < 1)
{
return false;
}

var deniedTxs = new[]
{
Expand Down
12 changes: 1 addition & 11 deletions Lib9c.Policy/Policy/BlockPolicySource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace Nekoyume.Blockchain.Policy
{
public partial class BlockPolicySource
{
public const int MaxTransactionsPerBlock = 200;
public const int MaxTransactionsPerBlock = 80;

public static readonly TimeSpan BlockInterval = TimeSpan.FromSeconds(8);

Expand Down Expand Up @@ -246,16 +246,6 @@ internal IBlockPolicy GetPolicy(
transaction.Id);
}

if (transaction.MaxGasPrice * transaction.GasLimit >
blockChain
.GetWorldState()
.GetAccountState(ReservedAddresses.LegacyAccount)
.GetBalance(transaction.Signer, Currencies.Mead))
{
return new TxPolicyViolationException(
$"Transaction {transaction.Id} signer insufficient transaction fee",
transaction.Id);
}
}
catch (InvalidSignatureException)
{
Expand Down
4 changes: 2 additions & 2 deletions Lib9c/Action/BuyProduct0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private IWorld Buy(IActionContext context, IProductInfo productInfo, Address sel
.SetLegacyState(productAddress, Null.Value)
.SetLegacyState(productsStateAddress, productsState.Serialize())
.SetLegacyState(ProductReceipt.DeriveAddress(productId), receipt.Serialize())
.SetAvatarState(sellerAvatarAddress, sellerAvatarState)
.SetAvatarState(sellerAvatarAddress, sellerAvatarState, true, true, true, true)
.TransferAsset(context, context.Signer, feeStoreAddress, tax)
.TransferAsset(context, context.Signer, sellerAgentAddress, taxedPrice);

Expand Down Expand Up @@ -322,7 +322,7 @@ private static IWorld Buy_Order(PurchaseInfo purchaseInfo, IActionContext contex
states = states
.SetLegacyState(digestListAddress, digestList.Serialize())
.SetLegacyState(orderReceiptAddress, orderReceipt.Serialize())
.SetAvatarState(sellerAvatarAddress, sellerAvatarState);
.SetAvatarState(sellerAvatarAddress, sellerAvatarState, true, true, true, true);
states = states.SetLegacyState(shardedShopAddress, shardedShopState.Serialize());
return states;
}
Expand Down
8 changes: 7 additions & 1 deletion Lib9c/Action/MigrationAvatarState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ public override IWorld Execute(IActionContext context)
foreach (var rawAvatar in avatarStates)
{
var avatarState = new AvatarState(rawAvatar);
states = states.SetAvatarState(avatarState.address, avatarState);
states = states.SetAvatarState(
avatarState.address,
avatarState,
true,
true,
true,
true);
}

return states;
Expand Down
2 changes: 1 addition & 1 deletion Lib9c/Action/Sell6.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public override IWorld Execute(IActionContext context)
result.id = mail.id;
avatarState.Update(mail);

states = states.SetAvatarState(sellerAvatarAddress, avatarState);
states = states.SetAvatarState(sellerAvatarAddress, avatarState, true, false, false, false);
sw.Stop();
Log.Verbose("{AddressesHex}Sell Set AvatarState: {Elapsed}", addressesHex, sw.Elapsed);
sw.Restart();
Expand Down
3 changes: 2 additions & 1 deletion Lib9c/Action/UnlockEquipmentRecipe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public override IWorld Execute(IActionContext context)
if (states.TryGetAvatarState(context.Signer, AvatarAddress, out AvatarState avatarState))
{
worldInformation = avatarState.worldInformation;
states = states.SetAvatarState(AvatarAddress, avatarState);
states = states
.SetAvatarState(AvatarAddress, avatarState, true, true, true, true);
}
else
{
Expand Down

0 comments on commit c5abc6a

Please sign in to comment.