Skip to content

Commit 46cff67

Browse files
authored
Merge pull request #3973 from riemannulus/fix/unvalidate-action-scheme
fix: do not check action is valid when append block
2 parents 57a4569 + b0801ac commit 46cff67

File tree

4 files changed

+6
-64
lines changed

4 files changed

+6
-64
lines changed

CHANGES.md

+6
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@ To be released.
1818

1919
### Behavioral changes
2020

21+
- There is no longer a check at block validation time to see
22+
if the actions contained in a block are interpretable. [[#3973]]
23+
2124
### Bug fixes
2225

2326
### Dependencies
2427

2528
### CLI tools
2629

2730

31+
[#3973]: https://github.com/planetarium/libplanet/pull/3973
32+
33+
2834
Version 5.3.1
2935
-------------
3036

src/Libplanet/Blockchain/BlockChain.Validate.cs

-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Linq;
55
using System.Numerics;
66
using System.Security.Cryptography;
7-
using Bencodex.Types;
87
using Libplanet.Action;
98
using Libplanet.Action.State;
109
using Libplanet.Common;
@@ -199,17 +198,6 @@ internal Dictionary<Address, long> ValidateBlockNonces(
199198
return nonceDeltas;
200199
}
201200

202-
internal void ValidateBlockLoadActions(Block block)
203-
{
204-
foreach (Transaction tx in block.Transactions)
205-
{
206-
foreach (IValue rawAction in tx.Actions)
207-
{
208-
_ = ActionEvaluator.ActionLoader.LoadAction(block.Index, rawAction);
209-
}
210-
}
211-
}
212-
213201
internal void ValidateBlock(Block block)
214202
{
215203
if (block.Index <= 0)

src/Libplanet/Blockchain/BlockChain.cs

-2
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,6 @@ internal void Append(
813813
.ToDictionary(signer => signer, signer => Store.GetTxNonce(Id, signer)),
814814
block);
815815

816-
ValidateBlockLoadActions(block);
817-
818816
if (Policy.ValidateNextBlock(this, block) is { } bpve)
819817
{
820818
throw bpve;

test/Libplanet.Tests/Blockchain/BlockChainTest.Append.cs

-50
Original file line numberDiff line numberDiff line change
@@ -651,56 +651,6 @@ void AssertTxIdSetEqual(
651651
_blockChain.StagePolicy.Iterate(_blockChain, filtered: false).Select(tx => tx.Id));
652652
}
653653

654-
[SkippableFact]
655-
public void CannotAppendBlockWithInvalidActions()
656-
{
657-
var txSigner = new PrivateKey();
658-
var unsignedInvalidTx = new UnsignedTx(
659-
new TxInvoice(
660-
_blockChain.Genesis.Hash,
661-
DateTimeOffset.UtcNow,
662-
new TxActionList((IValue)List.Empty.Add(new Text("Foo")))), // Invalid action
663-
new TxSigningMetadata(txSigner.PublicKey, 1));
664-
var invalidTx = new Transaction(
665-
unsignedInvalidTx, unsignedInvalidTx.CreateSignature(txSigner));
666-
var txs = new[]
667-
{
668-
Transaction.Create(
669-
nonce: 0,
670-
privateKey: txSigner,
671-
genesisHash: _blockChain.Genesis.Hash,
672-
actions: Array.Empty<DumbAction>().ToPlainValues()),
673-
invalidTx,
674-
Transaction.Create(
675-
nonce: 2,
676-
privateKey: txSigner,
677-
genesisHash: _blockChain.Genesis.Hash,
678-
actions: Array.Empty<DumbAction>().ToPlainValues()),
679-
}.OrderBy(tx => tx.Id);
680-
var evs = Array.Empty<EvidenceBase>();
681-
682-
var metadata = new BlockMetadata(
683-
index: 1L,
684-
timestamp: DateTimeOffset.UtcNow,
685-
publicKey: _fx.Proposer.PublicKey,
686-
previousHash: _blockChain.Genesis.Hash,
687-
txHash: BlockContent.DeriveTxHash(txs),
688-
lastCommit: null,
689-
evidenceHash: null);
690-
var preEval = new PreEvaluationBlock(
691-
preEvaluationBlockHeader: new PreEvaluationBlockHeader(
692-
metadata, metadata.DerivePreEvaluationHash()),
693-
transactions: txs,
694-
evidence: evs);
695-
var block = preEval.Sign(
696-
_fx.Proposer,
697-
(HashDigest<SHA256>)_blockChain.GetNextStateRootHash(_blockChain.Tip.Hash));
698-
699-
Assert.Throws<InvalidActionException>(
700-
() => _blockChain.Append(block, TestUtils.CreateBlockCommit(block)));
701-
Assert.Equal(0, _blockChain.Tip.Index);
702-
}
703-
704654
[SkippableFact]
705655
public void DoesNotMigrateStateWithoutAction()
706656
{

0 commit comments

Comments
 (0)