From 247f07cc8df9e3c76fb690bb739c0a3c8d8c191b Mon Sep 17 00:00:00 2001 From: Suho Lee Date: Tue, 22 Oct 2024 13:09:12 +0900 Subject: [PATCH] fix: do not check action is valid when append block --- CHANGES.md | 6 +++ .../Blockchain/BlockChain.Validate.cs | 12 ----- src/Libplanet/Blockchain/BlockChain.cs | 2 - .../Blockchain/BlockChainTest.Append.cs | 50 ------------------- 4 files changed, 6 insertions(+), 64 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index ece0cae7bab..39361c9c9b5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,6 +18,9 @@ To be released. ### Behavioral changes + - There is no longer a check at block validation time to see + if the actions contained in a block are interpretable. [[#3972]] + ### Bug fixes ### Dependencies @@ -25,6 +28,9 @@ To be released. ### CLI tools +[#3972]: https://github.com/planetarium/libplanet/pull/3972 + + Version 5.3.1 ------------- diff --git a/src/Libplanet/Blockchain/BlockChain.Validate.cs b/src/Libplanet/Blockchain/BlockChain.Validate.cs index c471fb5661b..c353af29e6c 100644 --- a/src/Libplanet/Blockchain/BlockChain.Validate.cs +++ b/src/Libplanet/Blockchain/BlockChain.Validate.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Numerics; using System.Security.Cryptography; -using Bencodex.Types; using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Common; @@ -199,17 +198,6 @@ internal Dictionary ValidateBlockNonces( return nonceDeltas; } - internal void ValidateBlockLoadActions(Block block) - { - foreach (Transaction tx in block.Transactions) - { - foreach (IValue rawAction in tx.Actions) - { - _ = ActionEvaluator.ActionLoader.LoadAction(block.Index, rawAction); - } - } - } - internal void ValidateBlock(Block block) { if (block.Index <= 0) diff --git a/src/Libplanet/Blockchain/BlockChain.cs b/src/Libplanet/Blockchain/BlockChain.cs index 856403dd71e..fa1fe6ce24f 100644 --- a/src/Libplanet/Blockchain/BlockChain.cs +++ b/src/Libplanet/Blockchain/BlockChain.cs @@ -813,8 +813,6 @@ internal void Append( .ToDictionary(signer => signer, signer => Store.GetTxNonce(Id, signer)), block); - ValidateBlockLoadActions(block); - if (Policy.ValidateNextBlock(this, block) is { } bpve) { throw bpve; diff --git a/test/Libplanet.Tests/Blockchain/BlockChainTest.Append.cs b/test/Libplanet.Tests/Blockchain/BlockChainTest.Append.cs index bfd48c17dab..610b5112037 100644 --- a/test/Libplanet.Tests/Blockchain/BlockChainTest.Append.cs +++ b/test/Libplanet.Tests/Blockchain/BlockChainTest.Append.cs @@ -651,56 +651,6 @@ void AssertTxIdSetEqual( _blockChain.StagePolicy.Iterate(_blockChain, filtered: false).Select(tx => tx.Id)); } - [SkippableFact] - public void CannotAppendBlockWithInvalidActions() - { - var txSigner = new PrivateKey(); - var unsignedInvalidTx = new UnsignedTx( - new TxInvoice( - _blockChain.Genesis.Hash, - DateTimeOffset.UtcNow, - new TxActionList((IValue)List.Empty.Add(new Text("Foo")))), // Invalid action - new TxSigningMetadata(txSigner.PublicKey, 1)); - var invalidTx = new Transaction( - unsignedInvalidTx, unsignedInvalidTx.CreateSignature(txSigner)); - var txs = new[] - { - Transaction.Create( - nonce: 0, - privateKey: txSigner, - genesisHash: _blockChain.Genesis.Hash, - actions: Array.Empty().ToPlainValues()), - invalidTx, - Transaction.Create( - nonce: 2, - privateKey: txSigner, - genesisHash: _blockChain.Genesis.Hash, - actions: Array.Empty().ToPlainValues()), - }.OrderBy(tx => tx.Id); - var evs = Array.Empty(); - - var metadata = new BlockMetadata( - index: 1L, - timestamp: DateTimeOffset.UtcNow, - publicKey: _fx.Proposer.PublicKey, - previousHash: _blockChain.Genesis.Hash, - txHash: BlockContent.DeriveTxHash(txs), - lastCommit: null, - evidenceHash: null); - var preEval = new PreEvaluationBlock( - preEvaluationBlockHeader: new PreEvaluationBlockHeader( - metadata, metadata.DerivePreEvaluationHash()), - transactions: txs, - evidence: evs); - var block = preEval.Sign( - _fx.Proposer, - (HashDigest)_blockChain.GetNextStateRootHash(_blockChain.Tip.Hash)); - - Assert.Throws( - () => _blockChain.Append(block, TestUtils.CreateBlockCommit(block))); - Assert.Equal(0, _blockChain.Tip.Index); - } - [SkippableFact] public void DoesNotMigrateStateWithoutAction() {