From c0f2314845b57ffd7a5ecd0e75ee3f9deefaaf9b Mon Sep 17 00:00:00 2001 From: Say Cheong Date: Fri, 3 Nov 2023 15:32:26 +0900 Subject: [PATCH 1/4] Updated UpdatedAddresses description --- Libplanet.Types/Tx/ITxInvoice.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Libplanet.Types/Tx/ITxInvoice.cs b/Libplanet.Types/Tx/ITxInvoice.cs index 12305254846..140be4cbac3 100644 --- a/Libplanet.Types/Tx/ITxInvoice.cs +++ b/Libplanet.Types/Tx/ITxInvoice.cs @@ -19,10 +19,21 @@ namespace Libplanet.Types.Tx public interface ITxInvoice : IEquatable { /// - /// An approximated list of addresses whose states would be affected by actions in this - /// transaction. However, it could be wrong. + /// + /// A deprecated property which was used as an approximated list of addresses whose states + /// would be affected by actions in this transaction. + /// + /// + /// This is no longer officially supported in the sense that a + /// cannot be created with a non-empty set of es through normal means + /// (i.e. using intended APIs). + /// + /// + /// It is still possible to create a through other means, + /// such as creating a payload directly by assigning appropriate values and signing + /// an "unsigned transaction". This is not recommended. + /// /// - // See also https://github.com/planetarium/libplanet/issues/368 IImmutableSet
UpdatedAddresses { get; } /// From 34ad9e2385cfdaa57b9da2d257ea4bc55223739e Mon Sep 17 00:00:00 2001 From: Say Cheong Date: Fri, 3 Nov 2023 16:57:48 +0900 Subject: [PATCH 2/4] Remove public updatedAddresses parameter from TxInvoice --- .../Consensus/ContextNonProposerTest.cs | 2 - .../Blockchain/BlockChainTest.Append.cs | 1 - .../Blockchain/BlockChainTest.ProposeBlock.cs | 1 - Libplanet.Tests/Blocks/BlockContentTest.cs | 16 ++++-- .../Fixtures/BlockContentFixture.cs | 20 +++---- .../Tx/TransactionExtensionsTest.cs | 5 +- Libplanet.Tests/Tx/TransactionTest.cs | 19 ++++--- Libplanet.Tests/Tx/TxInvoiceTest.cs | 26 +++++---- Libplanet.Tests/Tx/UnsignedTxTest.cs | 14 +++-- Libplanet.Types/AssemblyInfo.cs | 3 + Libplanet.Types/Tx/Transaction.cs | 3 +- Libplanet.Types/Tx/TxInvoice.cs | 55 +++++++++++++------ 12 files changed, 98 insertions(+), 67 deletions(-) create mode 100644 Libplanet.Types/AssemblyInfo.cs diff --git a/Libplanet.Net.Tests/Consensus/ContextNonProposerTest.cs b/Libplanet.Net.Tests/Consensus/ContextNonProposerTest.cs index 2f88c593df5..0a1dd182efd 100644 --- a/Libplanet.Net.Tests/Consensus/ContextNonProposerTest.cs +++ b/Libplanet.Net.Tests/Consensus/ContextNonProposerTest.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Collections.Immutable; using System.Security.Cryptography; using System.Text.Json; using System.Threading.Tasks; @@ -367,7 +366,6 @@ message is ConsensusPreCommitMsg commit && var unsignedInvalidTx = new UnsignedTx( new TxInvoice( blockChain.Genesis.Hash, - ImmutableHashSet
.Empty, DateTimeOffset.UtcNow, new TxActionList((IValue)List.Empty.Add(new Text("Foo")))), // Invalid action new TxSigningMetadata(txSigner.PublicKey, 0)); diff --git a/Libplanet.Tests/Blockchain/BlockChainTest.Append.cs b/Libplanet.Tests/Blockchain/BlockChainTest.Append.cs index 18f674f76a3..611ef4dbb07 100644 --- a/Libplanet.Tests/Blockchain/BlockChainTest.Append.cs +++ b/Libplanet.Tests/Blockchain/BlockChainTest.Append.cs @@ -628,7 +628,6 @@ public void CannotAppendBlockWithInvalidActions() var unsignedInvalidTx = new UnsignedTx( new TxInvoice( _blockChain.Genesis.Hash, - ImmutableHashSet
.Empty, DateTimeOffset.UtcNow, new TxActionList((IValue)List.Empty.Add(new Text("Foo")))), // Invalid action new TxSigningMetadata(txSigner.PublicKey, 1)); diff --git a/Libplanet.Tests/Blockchain/BlockChainTest.ProposeBlock.cs b/Libplanet.Tests/Blockchain/BlockChainTest.ProposeBlock.cs index e78bc7b3bc0..26c5586f243 100644 --- a/Libplanet.Tests/Blockchain/BlockChainTest.ProposeBlock.cs +++ b/Libplanet.Tests/Blockchain/BlockChainTest.ProposeBlock.cs @@ -665,7 +665,6 @@ public void MarkTransactionsToIgnoreWhileProposing() var unsignedInvalidTx = new UnsignedTx( new TxInvoice( _blockChain.Genesis.Hash, - ImmutableHashSet
.Empty, DateTimeOffset.UtcNow, new TxActionList((IValue)List.Empty.Add(new Text("Foo")))), // Invalid action new TxSigningMetadata(keyB.PublicKey, 1)); diff --git a/Libplanet.Tests/Blocks/BlockContentTest.cs b/Libplanet.Tests/Blocks/BlockContentTest.cs index 5da1fff3498..f7ea2619807 100644 --- a/Libplanet.Tests/Blocks/BlockContentTest.cs +++ b/Libplanet.Tests/Blocks/BlockContentTest.cs @@ -78,9 +78,11 @@ public void TransactionsWithDuplicateNonce() new UnsignedTx( new TxInvoice( genesisHash: GenesisHash, - updatedAddresses: new[] { Block1Tx1.Signer }, - timestamp: Block1Tx1.Timestamp - ), + updatedAddresses: new AddressSet(new[] { Block1Tx1.Signer }), + timestamp: Block1Tx1.Timestamp, + actions: TxActionList.Empty, + maxGasPrice: null, + gasLimit: null), new TxSigningMetadata(Block1Tx1.PublicKey, nonce: 1L) ), signature: ByteUtil.ParseHexToImmutable( @@ -111,9 +113,11 @@ public void TransactionsWithMissingNonce() new UnsignedTx( new TxInvoice( genesisHash: GenesisHash, - updatedAddresses: new[] { Block1Tx1.Signer }, - timestamp: Block1Tx1.Timestamp - ), + updatedAddresses: new AddressSet(new[] { Block1Tx1.Signer }), + timestamp: Block1Tx1.Timestamp, + actions: TxActionList.Empty, + maxGasPrice: null, + gasLimit: null), new TxSigningMetadata(Block1Tx1.PublicKey, nonce: 3L) ), signature: ByteUtil.ParseHexToImmutable( diff --git a/Libplanet.Tests/Fixtures/BlockContentFixture.cs b/Libplanet.Tests/Fixtures/BlockContentFixture.cs index 490f323483f..884ef39f5b2 100644 --- a/Libplanet.Tests/Fixtures/BlockContentFixture.cs +++ b/Libplanet.Tests/Fixtures/BlockContentFixture.cs @@ -74,13 +74,14 @@ public BlockContentFixture() new UnsignedTx( new TxInvoice( genesisHash: GenesisHash, - updatedAddresses: new[] { Block1Tx0Key.Address }, + updatedAddresses: new AddressSet(new[] { Block1Tx0Key.Address }), timestamp: new DateTimeOffset(2021, 9, 6, 17, 0, 1, 1, default), actions: new TxActionList(new IAction[] { Arithmetic.Add(10), Arithmetic.Add(50), Arithmetic.Sub(25), - }.ToPlainValues()) - ), + }.ToPlainValues()), + maxGasPrice: null, + gasLimit: null), new TxSigningMetadata(Block1Tx0Key.PublicKey, nonce: 0L) ), signature: ByteUtil.ParseHexToImmutable( @@ -94,19 +95,18 @@ public BlockContentFixture() new UnsignedTx( new TxInvoice( genesisHash: GenesisHash, - updatedAddresses: new[] { Block1Tx1Key.Address }, + updatedAddresses: new AddressSet(new[] { Block1Tx1Key.Address }), timestamp: new DateTimeOffset(2021, 9, 6, 17, 0, 1, 1, default), actions: new TxActionList(new IAction[] { Arithmetic.Add(30), - }.ToPlainValues()) - ), - new TxSigningMetadata(Block1Tx1Key.PublicKey, nonce: 1L) - ), + }.ToPlainValues()), + maxGasPrice: null, + gasLimit: null), + new TxSigningMetadata(Block1Tx1Key.PublicKey, nonce: 1L)), signature: ByteUtil.ParseHexToImmutable( "3045022100abe3caabf2a46a297f2e4496f2c46d7e2f723e75fc42025d19f3ed7fce382" + - "d4e02200ffd36f7bef759b6c7ab43bc0f8959a0c463f88fd0f1faeaa209a8661506c4f0" - ) + "d4e02200ffd36f7bef759b6c7ab43bc0f8959a0c463f88fd0f1faeaa209a8661506c4f0") ); var block1Transactions = new List() { Block1Tx0, Block1Tx1 } diff --git a/Libplanet.Tests/Tx/TransactionExtensionsTest.cs b/Libplanet.Tests/Tx/TransactionExtensionsTest.cs index 4f95a97df11..69b77696fa6 100644 --- a/Libplanet.Tests/Tx/TransactionExtensionsTest.cs +++ b/Libplanet.Tests/Tx/TransactionExtensionsTest.cs @@ -34,8 +34,9 @@ public void Sign() genesisHash, updatedAddresses, timestamp, - actions - ); + actions, + null, + null); var privateKey = new PrivateKey("51fb8c2eb261ed761429c297dd1f8952c8ce327d2ec2ec5bcc7728e3362627c2"); Transaction tx = invoice.Sign(privateKey, 123L); diff --git a/Libplanet.Tests/Tx/TransactionTest.cs b/Libplanet.Tests/Tx/TransactionTest.cs index de78f080ad5..05b5b1c68d4 100644 --- a/Libplanet.Tests/Tx/TransactionTest.cs +++ b/Libplanet.Tests/Tx/TransactionTest.cs @@ -344,8 +344,9 @@ public void Equality() genesisHash, updatedAddresses, timestamp, - actions - ); + actions, + null, + null); var privateKey = new PrivateKey("51fb8c2eb261ed761429c297dd1f8952c8ce327d2ec2ec5bcc7728e3362627c2"); PublicKey publicKey = privateKey.PublicKey; @@ -372,10 +373,11 @@ public void Equality() { var diffInvoice = new TxInvoice( i == 0 ? (BlockHash?)null : invoice.GenesisHash, - i == 1 ? null : invoice.UpdatedAddresses, - i == 2 ? (DateTimeOffset?)DateTimeOffset.MinValue : invoice.Timestamp, - i == 3 ? null : invoice.Actions - ); + i == 1 ? AddressSet.Empty : invoice.UpdatedAddresses, + i == 2 ? DateTimeOffset.MinValue : invoice.Timestamp, + i == 3 ? TxActionList.Empty : invoice.Actions, + null, + null); var diffSigningMetadata = new TxSigningMetadata( i == 4 ? wrongKey.PublicKey : signingMetadata.PublicKey, i == 5 ? 456L : signingMetadata.Nonce @@ -422,8 +424,9 @@ public void JsonSerialization() genesisHash, updatedAddresses, timestamp, - actions - ); + actions, + null, + null); var privateKey = new PrivateKey("51fb8c2eb261ed761429c297dd1f8952c8ce327d2ec2ec5bcc7728e3362627c2"); PublicKey publicKey = privateKey.PublicKey; diff --git a/Libplanet.Tests/Tx/TxInvoiceTest.cs b/Libplanet.Tests/Tx/TxInvoiceTest.cs index 4aa6697f555..f2dff62b59a 100644 --- a/Libplanet.Tests/Tx/TxInvoiceTest.cs +++ b/Libplanet.Tests/Tx/TxInvoiceTest.cs @@ -36,8 +36,9 @@ public void PlainConstructor() genesisHash, updatedAddresses, timestamp, - actions - ); + actions, + null, + null); Assert.Equal(genesisHash, invoice.GenesisHash); Assert.True(updatedAddresses.SetEquals(invoice.UpdatedAddresses)); Assert.Equal(timestamp, invoice.Timestamp); @@ -75,8 +76,9 @@ public void CopyConstructor() genesisHash, updatedAddresses, timestamp, - actions - ); + actions, + null, + null); var copy = new TxInvoice(original); Assert.Equal(genesisHash, copy.GenesisHash); Assert.True(updatedAddresses.SetEquals(copy.UpdatedAddresses)); @@ -109,14 +111,16 @@ public void Equality() genesisHash, updatedAddresses, timestamp, - actions - ); + actions, + null, + null); var invoice2 = new TxInvoice( genesisHash, updatedAddresses, timestamp, - actions - ); + actions, + null, + null); Assert.True(invoice1.Equals(invoice2)); Assert.True(invoice1.Equals((object)invoice2)); Assert.Equal(invoice1.GetHashCode(), invoice2.GetHashCode()); @@ -131,9 +135,9 @@ public void Equality() { var invoice = new TxInvoice( i == 0 ? (BlockHash?)null : genesisHash, - i == 1 ? null : updatedAddresses, - i == 2 ? (DateTimeOffset?)DateTimeOffset.MinValue : timestamp, - i == 3 ? null : actions, + i == 1 ? (IImmutableSet
)AddressSet.Empty : updatedAddresses, + i == 2 ? DateTimeOffset.MinValue : timestamp, + i == 3 ? TxActionList.Empty : actions, i == 4 ? (FungibleAssetValue?)null : FungibleAssetValue.FromRawValue( Currency.Uncapped( "FOO", diff --git a/Libplanet.Tests/Tx/UnsignedTxTest.cs b/Libplanet.Tests/Tx/UnsignedTxTest.cs index 9d6339d555b..6deb48b96cd 100644 --- a/Libplanet.Tests/Tx/UnsignedTxTest.cs +++ b/Libplanet.Tests/Tx/UnsignedTxTest.cs @@ -41,8 +41,9 @@ public UnsignedTxTest() genesisHash, updatedAddresses, timestamp, - actions - ); + actions, + null, + null); _signingMetadata = new TxSigningMetadata(PublicKey, 123L); } @@ -120,10 +121,11 @@ public void Equality() { var diffInvoice = new TxInvoice( i == 0 ? (BlockHash?)null : _invoice.GenesisHash, - i == 1 ? null : _invoice.UpdatedAddresses, - i == 2 ? (DateTimeOffset?)DateTimeOffset.MinValue : _invoice.Timestamp, - i == 3 ? null : _invoice.Actions - ); + i == 1 ? AddressSet.Empty : _invoice.UpdatedAddresses, + i == 2 ? DateTimeOffset.MinValue : _invoice.Timestamp, + i == 3 ? TxActionList.Empty : _invoice.Actions, + null, + null); var diffSigningMetadata = new TxSigningMetadata( i == 4 ? wrongKey.PublicKey : _signingMetadata.PublicKey, i == 5 ? 456L : _signingMetadata.Nonce diff --git a/Libplanet.Types/AssemblyInfo.cs b/Libplanet.Types/AssemblyInfo.cs new file mode 100644 index 00000000000..4d7077a7967 --- /dev/null +++ b/Libplanet.Types/AssemblyInfo.cs @@ -0,0 +1,3 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Libplanet.Tests")] diff --git a/Libplanet.Types/Tx/Transaction.cs b/Libplanet.Types/Tx/Transaction.cs index 4ed6f799916..49272b63803 100644 --- a/Libplanet.Types/Tx/Transaction.cs +++ b/Libplanet.Types/Tx/Transaction.cs @@ -261,8 +261,7 @@ public static Transaction Create( maxGasPrice, gasLimit, updatedAddresses, - timestamp - ); + timestamp); /// /// Encodes this into a array. diff --git a/Libplanet.Types/Tx/TxInvoice.cs b/Libplanet.Types/Tx/TxInvoice.cs index eac1242c9b5..102e6ef981f 100644 --- a/Libplanet.Types/Tx/TxInvoice.cs +++ b/Libplanet.Types/Tx/TxInvoice.cs @@ -23,7 +23,6 @@ public sealed class TxInvoice : ITxInvoice, IEquatable /// Creates a new instance by filling data for its fields. /// /// The value for . - /// The value for . /// The value for . /// The value of . /// The value of . @@ -32,21 +31,13 @@ public sealed class TxInvoice : ITxInvoice, IEquatable /// or is . public TxInvoice( BlockHash? genesisHash, - IImmutableSet
updatedAddresses, DateTimeOffset timestamp, TxActionList actions, FungibleAssetValue? maxGasPrice, long? gasLimit) { - if (updatedAddresses is null) - { - throw new ArgumentNullException(nameof(updatedAddresses)); - } - GenesisHash = genesisHash; - UpdatedAddresses = updatedAddresses is AddressSet set - ? set - : new AddressSet(updatedAddresses); + UpdatedAddresses = ImmutableHashSet
.Empty; Timestamp = timestamp; Actions = actions ?? throw new ArgumentNullException(nameof(actions)); MaxGasPrice = maxGasPrice; @@ -58,8 +49,6 @@ public TxInvoice( /// are some default values for some fields. ///
/// The value for . - /// The value for . - /// Empty by default. /// The value for . /// Time of creation by default. /// The value of . @@ -68,20 +57,16 @@ public TxInvoice( /// The value of limit. public TxInvoice( BlockHash? genesisHash = null, - IEnumerable
? updatedAddresses = null, DateTimeOffset? timestamp = null, TxActionList? actions = null, FungibleAssetValue? maxGasPrice = null, - long? gasLimit = null - ) + long? gasLimit = null) : this( genesisHash, - updatedAddresses?.ToImmutableHashSet() ?? ImmutableHashSet
.Empty, timestamp ?? DateTimeOffset.UtcNow, actions ?? TxActionList.Empty, maxGasPrice, - gasLimit - ) + gasLimit) { } @@ -101,6 +86,40 @@ public TxInvoice(ITxInvoice invoice) { } + /// + /// Creates a new instance by filling data for its fields. + /// + /// The value for . + /// The value for . + /// The value for . + /// The value of . + /// The value of . + /// The value of limit. + /// Thrown when + /// or is . + internal TxInvoice( + BlockHash? genesisHash, + IImmutableSet
updatedAddresses, + DateTimeOffset timestamp, + TxActionList actions, + FungibleAssetValue? maxGasPrice, + long? gasLimit) + { + if (updatedAddresses is null) + { + throw new ArgumentNullException(nameof(updatedAddresses)); + } + + GenesisHash = genesisHash; + UpdatedAddresses = updatedAddresses is AddressSet set + ? set + : new AddressSet(updatedAddresses); + Timestamp = timestamp; + Actions = actions ?? throw new ArgumentNullException(nameof(actions)); + MaxGasPrice = maxGasPrice; + GasLimit = gasLimit; + } + /// public BlockHash? GenesisHash { get; } From 26a5495030785a8a651e824bf66112b2c5de0030 Mon Sep 17 00:00:00 2001 From: Say Cheong Date: Fri, 3 Nov 2023 17:47:40 +0900 Subject: [PATCH 3/4] Remove public updatedAddresses parameter from Transaction.Create() --- .../GeneratedBlockChainFixture.cs | 24 ++- .../Commands/StoreCommandTest.cs | 4 +- Libplanet.Net.Tests/Consensus/ContextTest.cs | 5 +- Libplanet.Net.Tests/SwarmTest.Preload.cs | 4 +- Libplanet.Tests/Action/ActionEvaluatorTest.cs | 178 +++++++++++------- .../Blockchain/BlockChainTest.Append.cs | 8 +- .../Blockchain/BlockChainTest.Internals.cs | 4 +- Libplanet.Tests/Blockchain/BlockChainTest.cs | 40 ++-- Libplanet.Tests/Fixtures/IntegerSet.cs | 16 +- Libplanet.Tests/Store/StoreFixture.cs | 1 - Libplanet.Tests/Store/StoreTest.cs | 4 +- Libplanet.Tests/Tx/TransactionTest.cs | 25 +-- Libplanet.Tests/Tx/TxFixture.cs | 22 ++- Libplanet.Types/AssemblyInfo.cs | 1 + Libplanet.Types/Tx/Transaction.cs | 6 - Libplanet/Blockchain/BlockChain.cs | 4 - 16 files changed, 174 insertions(+), 172 deletions(-) diff --git a/Libplanet.Explorer.Tests/GeneratedBlockChainFixture.cs b/Libplanet.Explorer.Tests/GeneratedBlockChainFixture.cs index 16855ebf00a..df648020b28 100644 --- a/Libplanet.Explorer.Tests/GeneratedBlockChainFixture.cs +++ b/Libplanet.Explorer.Tests/GeneratedBlockChainFixture.cs @@ -189,16 +189,20 @@ private Transaction var random = new System.Random(seed); var addr = pk.Address; var bal = (int)(Chain.GetBalance(addr, TestCurrency).MajorUnit & int.MaxValue); - return Transaction.Create( - nonce, - pk, - Chain.Genesis.Hash, - random.Next() % 2 == 0 - ? GetRandomActions(random.Next()).ToPlainValues() - : ImmutableHashSet.Empty.ToPlainValues(), - null, - null, - GetRandomAddresses(random.Next())); + return + new Transaction( + new UnsignedTx( + new TxInvoice( + genesisHash: Chain.Genesis.Hash, + updatedAddresses: GetRandomAddresses(random.Next()), + timestamp: DateTimeOffset.UtcNow, + actions: new TxActionList(random.Next() % 2 == 0 + ? GetRandomActions(random.Next()).ToPlainValues() + : ImmutableHashSet.Empty.ToPlainValues()), + maxGasPrice: null, + gasLimit: null), + new TxSigningMetadata(pk.PublicKey, nonce)), + pk); } private ImmutableArray GetRandomActions(int seed) diff --git a/Libplanet.Extensions.Cocona.Tests/Commands/StoreCommandTest.cs b/Libplanet.Extensions.Cocona.Tests/Commands/StoreCommandTest.cs index 4d096b96545..d33f7db4e89 100644 --- a/Libplanet.Extensions.Cocona.Tests/Commands/StoreCommandTest.cs +++ b/Libplanet.Extensions.Cocona.Tests/Commands/StoreCommandTest.cs @@ -369,8 +369,6 @@ private Transaction DummyTransaction() new[] { new Utils.DummyAction() }.ToPlainValues(), null, null, - null, - DateTimeOffset.UtcNow - ); + DateTimeOffset.UtcNow); } } diff --git a/Libplanet.Net.Tests/Consensus/ContextTest.cs b/Libplanet.Net.Tests/Consensus/ContextTest.cs index b54ee154d70..c93f8942014 100644 --- a/Libplanet.Net.Tests/Consensus/ContextTest.cs +++ b/Libplanet.Net.Tests/Consensus/ContextTest.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Immutable; using System.Linq; using System.Text.Json; using System.Threading.Tasks; @@ -362,9 +361,7 @@ void BroadcastMessage(ConsensusMsg message) => nonce: 0, privateKey: TestUtils.PrivateKeys[1], genesisHash: blockChain.Genesis.Hash, - actions: new[] { action }.ToPlainValues(), - updatedAddresses: ImmutableHashSet.Create(DelayAction.TrivialUpdatedAddress) - ); + actions: new[] { action }.ToPlainValues()); blockChain.StageTransaction(tx); var block = blockChain.ProposeBlock(TestUtils.PrivateKeys[1]); diff --git a/Libplanet.Net.Tests/SwarmTest.Preload.cs b/Libplanet.Net.Tests/SwarmTest.Preload.cs index f82c69d8abf..a755b8bc629 100644 --- a/Libplanet.Net.Tests/SwarmTest.Preload.cs +++ b/Libplanet.Net.Tests/SwarmTest.Preload.cs @@ -466,9 +466,7 @@ public async Task PreloadWithFailedActions() new[] { action }.ToPlainValues(), null, null, - ImmutableHashSet
.Empty, - DateTimeOffset.UtcNow - ); + DateTimeOffset.UtcNow); Block block = minerChain.ProposeBlock( ChainPrivateKey, diff --git a/Libplanet.Tests/Action/ActionEvaluatorTest.cs b/Libplanet.Tests/Action/ActionEvaluatorTest.cs index 9595adc75f7..7c55328bc08 100644 --- a/Libplanet.Tests/Action/ActionEvaluatorTest.cs +++ b/Libplanet.Tests/Action/ActionEvaluatorTest.cs @@ -277,32 +277,50 @@ DumbAction MakeAction(Address address, char identifier, Address? transferTo = nu Transaction[] block1Txs = { - Transaction.Create( - nonce: 0, - privateKey: _txFx.PrivateKey1, - genesisHash: genesis.Hash, - actions: new[] - { - MakeAction(addresses[0], 'A', addresses[1]), - MakeAction(addresses[1], 'B', addresses[2]), - }.ToPlainValues(), - updatedAddresses: new[] { addresses[0], addresses[1] }.ToImmutableHashSet(), - timestamp: DateTimeOffset.MinValue.AddSeconds(2)), - Transaction.Create( - nonce: 0, - privateKey: _txFx.PrivateKey2, - genesisHash: genesis.Hash, - actions: new[] - { - MakeAction(addresses[2], 'C', addresses[3]), - }.ToPlainValues(), - timestamp: DateTimeOffset.MinValue.AddSeconds(4)), - Transaction.Create( - nonce: 0, - privateKey: _txFx.PrivateKey3, - genesisHash: genesis.Hash, - actions: Array.Empty().ToPlainValues(), - timestamp: DateTimeOffset.MinValue.AddSeconds(7)), + new Transaction( + new UnsignedTx( + new TxInvoice( + genesisHash: genesis.Hash, + updatedAddresses: new[] + { + addresses[0], + addresses[1], + }.ToImmutableHashSet(), + timestamp: DateTimeOffset.MinValue.AddSeconds(2), + actions: new TxActionList(new[] + { + MakeAction(addresses[0], 'A', addresses[1]), + MakeAction(addresses[1], 'B', addresses[2]), + }.ToPlainValues()), + maxGasPrice: null, + gasLimit: null), + new TxSigningMetadata(_txFx.PrivateKey1.PublicKey, 0)), + _txFx.PrivateKey1), + new Transaction( + new UnsignedTx( + new TxInvoice( + genesisHash: genesis.Hash, + updatedAddresses: ImmutableHashSet
.Empty, + timestamp: DateTimeOffset.MinValue.AddSeconds(4), + actions: new TxActionList(new[] + { + MakeAction(addresses[2], 'C', addresses[3]), + }.ToPlainValues()), + maxGasPrice: null, + gasLimit: null), + new TxSigningMetadata(_txFx.PrivateKey2.PublicKey, 0)), + _txFx.PrivateKey2), + new Transaction( + new UnsignedTx( + new TxInvoice( + genesisHash: genesis.Hash, + updatedAddresses: ImmutableHashSet
.Empty, + timestamp: DateTimeOffset.MinValue.AddSeconds(7), + actions: TxActionList.Empty, + maxGasPrice: null, + gasLimit: null), + new TxSigningMetadata(_txFx.PrivateKey3.PublicKey, 0)), + _txFx.PrivateKey3), }; foreach ((var tx, var i) in block1Txs.Zip( Enumerable.Range(0, block1Txs.Length), (x, y) => (x, y))) @@ -384,37 +402,55 @@ DumbAction MakeAction(Address address, char identifier, Address? transferTo = nu // Note that these timestamps in themselves does not have any meanings but are // only arbitrary. These purpose to make their evaluation order in a block // equal to the order we (the test) intend: - Transaction.Create( - 0, - _txFx.PrivateKey1, - genesis.Hash, - new[] { MakeAction(addresses[0], 'D') }.ToPlainValues(), - updatedAddresses: new[] { addresses[0] }.ToImmutableHashSet(), - timestamp: DateTimeOffset.MinValue.AddSeconds(1)), - Transaction.Create( - 0, - _txFx.PrivateKey2, - genesis.Hash, - new[] { MakeAction(addresses[3], 'E') }.ToPlainValues(), - updatedAddresses: new[] { addresses[3] }.ToImmutableHashSet(), - timestamp: DateTimeOffset.MinValue.AddSeconds(2)), - Transaction.Create( - 0, - _txFx.PrivateKey3, - genesis.Hash, - new[] - { - new DumbAction( - addresses[4], - "RecordRehearsal", - transferFrom: addresses[0], - transferTo: addresses[4], - transferAmount: 8, - recordRehearsal: true, - recordRandom: true), - }.ToPlainValues(), - updatedAddresses: new[] { addresses[4] }.ToImmutableHashSet(), - timestamp: DateTimeOffset.MinValue.AddSeconds(4)), + new Transaction( + new UnsignedTx( + new TxInvoice( + genesisHash: genesis.Hash, + updatedAddresses: new[] { addresses[0] }.ToImmutableHashSet(), + timestamp: DateTimeOffset.MinValue.AddSeconds(1), + actions: new TxActionList(new[] + { + MakeAction(addresses[0], 'D'), + }.ToPlainValues()), + maxGasPrice: null, + gasLimit: null), + new TxSigningMetadata(_txFx.PrivateKey1.PublicKey, 0)), + _txFx.PrivateKey1), + new Transaction( + new UnsignedTx( + new TxInvoice( + genesisHash: genesis.Hash, + updatedAddresses: new[] { addresses[3] }.ToImmutableHashSet(), + timestamp: DateTimeOffset.MinValue.AddSeconds(2), + actions: new TxActionList(new[] + { + MakeAction(addresses[3], 'E'), + }.ToPlainValues()), + maxGasPrice: null, + gasLimit: null), + new TxSigningMetadata(_txFx.PrivateKey2.PublicKey, 0)), + _txFx.PrivateKey2), + new Transaction( + new UnsignedTx( + new TxInvoice( + genesisHash: genesis.Hash, + updatedAddresses: new[] { addresses[4] }.ToImmutableHashSet(), + timestamp: DateTimeOffset.MinValue.AddSeconds(4), + actions: new TxActionList(new[] + { + new DumbAction( + addresses[4], + "RecordRehearsal", + transferFrom: addresses[0], + transferTo: addresses[4], + transferAmount: 8, + recordRehearsal: true, + recordRandom: true), + }.ToPlainValues()), + maxGasPrice: null, + gasLimit: null), + new TxSigningMetadata(_txFx.PrivateKey3.PublicKey, 0)), + _txFx.PrivateKey3), }; foreach ((var tx, var i) in block2Txs.Zip( Enumerable.Range(0, block2Txs.Length), (x, y) => (x, y))) @@ -623,7 +659,6 @@ public void EvaluateTxResultThrowingException() new[] { action }.ToPlainValues(), null, null, - ImmutableHashSet
.Empty, DateTimeOffset.UtcNow); var txs = new Transaction[] { tx }; var hash = new BlockHash(GetRandomBytes(BlockHash.Size)); @@ -838,17 +873,22 @@ public void OrderTxsForEvaluation( .Select(signerNoncePair => { Address targetAddress = signerNoncePair.signer.Address; - return Transaction.Create( - nonce: signerNoncePair.nonce, - privateKey: signerNoncePair.signer, - genesisHash: null, - actions: new[] - { - new RandomAction(signerNoncePair.signer.Address), - }.ToPlainValues(), - updatedAddresses: ImmutableHashSet.Create(targetAddress), - timestamp: epoch - ); + return new Transaction( + new UnsignedTx( + new TxInvoice( + genesisHash: null, + updatedAddresses: ImmutableHashSet.Create(targetAddress), + timestamp: epoch, + actions: new TxActionList(new[] + { + new RandomAction(signerNoncePair.signer.Address), + }.ToPlainValues()), + maxGasPrice: null, + gasLimit: null), + new TxSigningMetadata( + signerNoncePair.signer.PublicKey, + signerNoncePair.nonce)), + signerNoncePair.signer); }).ToImmutableArray(); // Rearrange transactions so that transactions are not grouped by signers diff --git a/Libplanet.Tests/Blockchain/BlockChainTest.Append.cs b/Libplanet.Tests/Blockchain/BlockChainTest.Append.cs index 611ef4dbb07..be2c9bccf7f 100644 --- a/Libplanet.Tests/Blockchain/BlockChainTest.Append.cs +++ b/Libplanet.Tests/Blockchain/BlockChainTest.Append.cs @@ -639,17 +639,13 @@ public void CannotAppendBlockWithInvalidActions() nonce: 0, privateKey: txSigner, genesisHash: _blockChain.Genesis.Hash, - actions: Array.Empty().ToPlainValues(), - updatedAddresses: ImmutableHashSet
.Empty - ), + actions: Array.Empty().ToPlainValues()), invalidTx, Transaction.Create( nonce: 2, privateKey: txSigner, genesisHash: _blockChain.Genesis.Hash, - actions: Array.Empty().ToPlainValues(), - updatedAddresses: ImmutableHashSet
.Empty - ), + actions: Array.Empty().ToPlainValues()), }.OrderBy(tx => tx.Id); var metadata = new BlockMetadata( diff --git a/Libplanet.Tests/Blockchain/BlockChainTest.Internals.cs b/Libplanet.Tests/Blockchain/BlockChainTest.Internals.cs index f245047020a..a7bb90e670a 100644 --- a/Libplanet.Tests/Blockchain/BlockChainTest.Internals.cs +++ b/Libplanet.Tests/Blockchain/BlockChainTest.Internals.cs @@ -35,9 +35,7 @@ Transaction MkTx(PrivateKey key, long nonce, DateTimeOffset? ts = null) => Array.Empty().ToPlainValues(), null, null, - null, - ts ?? DateTimeOffset.UtcNow - ); + ts ?? DateTimeOffset.UtcNow); PrivateKey a = new PrivateKey(); PrivateKey b = new PrivateKey(); diff --git a/Libplanet.Tests/Blockchain/BlockChainTest.cs b/Libplanet.Tests/Blockchain/BlockChainTest.cs index 74593122d11..126c08638c5 100644 --- a/Libplanet.Tests/Blockchain/BlockChainTest.cs +++ b/Libplanet.Tests/Blockchain/BlockChainTest.cs @@ -597,22 +597,24 @@ public void ForkShouldSkipExecuteAndRenderGenesis() _ => _policy.BlockAction, stateStore, new SingleActionLoader(typeof(DumbAction))); + var privateKey = new PrivateKey(); var genesis = ProposeGenesisBlock( actionEvaluator, ProposeGenesis( GenesisProposer.PublicKey, transactions: new[] { - Transaction.Create( - nonce: 0, - privateKey: new PrivateKey(), - genesisHash: null, - actions: new[] { action }.ToPlainValues(), - maxGasPrice: null, - gasLimit: null, - updatedAddresses: ImmutableHashSet.Create(_fx.Address1), - timestamp: DateTimeOffset.UtcNow - ), + new Transaction( + new UnsignedTx( + new TxInvoice( + genesisHash: null, + updatedAddresses: ImmutableHashSet.Create(_fx.Address1), + timestamp: DateTimeOffset.UtcNow, + actions: new TxActionList(new[] { action }.ToPlainValues()), + maxGasPrice: null, + gasLimit: null), + new TxSigningMetadata(privateKey.PublicKey, 0)), + privateKey), }), privateKey: GenesisProposer); @@ -1887,13 +1889,17 @@ private void CreateWithGenesisBlock() .ToArray(); var customTxs = new[] { - Transaction.Create( - nonce: systemTxs.Length, - privateKey: privateKey, - genesisHash: null, - actions: customActions.ToPlainValues(), - updatedAddresses: addresses.ToImmutableHashSet() - ), + new Transaction( + new UnsignedTx( + new TxInvoice( + genesisHash: null, + updatedAddresses: addresses.ToImmutableHashSet(), + timestamp: DateTimeOffset.UtcNow, + actions: new TxActionList(customActions.ToPlainValues()), + maxGasPrice: null, + gasLimit: null), + new TxSigningMetadata(privateKey.PublicKey, systemTxs.Length)), + privateKey), }; var txs = systemTxs.Concat(customTxs).ToImmutableList(); var blockChainStates = new BlockChainStates( diff --git a/Libplanet.Tests/Fixtures/IntegerSet.cs b/Libplanet.Tests/Fixtures/IntegerSet.cs index 8f15aa25d49..6737dcda3ee 100644 --- a/Libplanet.Tests/Fixtures/IntegerSet.cs +++ b/Libplanet.Tests/Fixtures/IntegerSet.cs @@ -57,16 +57,12 @@ public IntegerSet( .Select(pair => new { State = (BigInteger)pair.State, pair.Key }) .Select(pair => new { Action = Arithmetic.Add(pair.State), pair.Key }) .Select(pair => - Transaction.Create( - 0, - pair.Key, - null, - new[] { pair.Action }.ToPlainValues(), - null, - null, - ImmutableHashSet
.Empty.Add(pair.Key.Address) - ) - ) + new Transaction( + new UnsignedTx( + new TxInvoice( + actions: new TxActionList(new[] { pair.Action.PlainValue })), + new TxSigningMetadata(pair.Key.PublicKey, 0)), + pair.Key)) .OrderBy(tx => tx.Id) .ToImmutableArray(); Miner = new PrivateKey(); diff --git a/Libplanet.Tests/Store/StoreFixture.cs b/Libplanet.Tests/Store/StoreFixture.cs index 6661eb2b7ca..67257768aa3 100644 --- a/Libplanet.Tests/Store/StoreFixture.cs +++ b/Libplanet.Tests/Store/StoreFixture.cs @@ -219,7 +219,6 @@ public Transaction MakeTransaction( actions?.ToPlainValues() ?? Array.Empty().ToPlainValues(), null, null, - updatedAddresses, timestamp ); } diff --git a/Libplanet.Tests/Store/StoreTest.cs b/Libplanet.Tests/Store/StoreTest.cs index 09a3da08d9b..4d48cfc92a9 100644 --- a/Libplanet.Tests/Store/StoreTest.cs +++ b/Libplanet.Tests/Store/StoreTest.cs @@ -741,9 +741,7 @@ int txNonce new[] { action }.ToPlainValues(), null, null, - ImmutableHashSet
.Empty, - DateTimeOffset.UtcNow - ); + DateTimeOffset.UtcNow); } const int taskCount = 5; diff --git a/Libplanet.Tests/Tx/TransactionTest.cs b/Libplanet.Tests/Tx/TransactionTest.cs index 05b5b1c68d4..192c5dbfb5c 100644 --- a/Libplanet.Tests/Tx/TransactionTest.cs +++ b/Libplanet.Tests/Tx/TransactionTest.cs @@ -137,7 +137,6 @@ public void CreateWithCustomActions() }.Select(x => x.PlainValue), null, null, - ImmutableHashSet
.Empty, timestamp ); @@ -179,25 +178,8 @@ public void CreateWithDefaultUpdatedAddresses() 0, _fx.PrivateKey1, null, - Array.Empty().Select(x => x.PlainValue) - ); + Array.Empty().Select(x => x.PlainValue)); Assert.Empty(emptyTx.UpdatedAddresses); - - Address updatedAddr = new PrivateKey().Address; - var txWithAddr = Transaction.Create( - 0, - _fx.PrivateKey1, - null, - _fx.TxWithActions.Actions, - null, - null, - new[] { updatedAddr }.ToImmutableHashSet() - ); - - Assert.Equal( - new[] { updatedAddr }.ToHashSet(), - txWithAddr.UpdatedAddresses.ToHashSet() - ); } [Fact] @@ -210,9 +192,7 @@ public void CreateWithDefaultTimestamp() null, Array.Empty().Select(x => x.PlainValue), null, - null, - ImmutableHashSet
.Empty - ); + null); DateTimeOffset rightAfter = DateTimeOffset.UtcNow; Assert.InRange(tx.Timestamp, rightBefore, rightAfter); @@ -230,7 +210,6 @@ public void CreateWithMissingRequiredArguments() Array.Empty().Select(x => x.PlainValue), null, null, - ImmutableHashSet
.Empty, DateTimeOffset.UtcNow ) ); diff --git a/Libplanet.Tests/Tx/TxFixture.cs b/Libplanet.Tests/Tx/TxFixture.cs index bf4f710b1ec..85ac0b3217e 100644 --- a/Libplanet.Tests/Tx/TxFixture.cs +++ b/Libplanet.Tests/Tx/TxFixture.cs @@ -80,16 +80,18 @@ public TxFixture(BlockHash? genesisHash) ZoneId = 10, }, }; - TxWithActions = Transaction.Create( - 0, - PrivateKey1, - genesisHash, - actions.ToPlainValues(), - updatedAddresses: ImmutableHashSet.Create( - new Address("c2a86014073d662a4a9bfcf9cb54263dfa4f5cbc") - ), - timestamp: timestamp - ); + TxWithActions = new Transaction( + new UnsignedTx( + new TxInvoice( + genesisHash: genesisHash, + updatedAddresses: ImmutableHashSet.Create( + new Address("c2a86014073d662a4a9bfcf9cb54263dfa4f5cbc")), + timestamp: timestamp, + actions: new TxActionList(actions.ToPlainValues()), + maxGasPrice: null, + gasLimit: null), + new TxSigningMetadata(PrivateKey1.PublicKey, 0)), + PrivateKey1); } public PrivateKey PrivateKey1 { get; } diff --git a/Libplanet.Types/AssemblyInfo.cs b/Libplanet.Types/AssemblyInfo.cs index 4d7077a7967..0b2dfbb919c 100644 --- a/Libplanet.Types/AssemblyInfo.cs +++ b/Libplanet.Types/AssemblyInfo.cs @@ -1,3 +1,4 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Libplanet.Tests")] +[assembly: InternalsVisibleTo("Libplanet.Explorer.Tests")] diff --git a/Libplanet.Types/Tx/Transaction.cs b/Libplanet.Types/Tx/Transaction.cs index 49272b63803..9d54135779c 100644 --- a/Libplanet.Types/Tx/Transaction.cs +++ b/Libplanet.Types/Tx/Transaction.cs @@ -233,8 +233,6 @@ public static Transaction Deserialize(byte[] bytes) /// The maximum gas price this transaction can pay fee. /// The maximum amount of gas this transaction can consume. /// - /// es whose - /// states affected by . /// The time this /// is created and signed. This goes to the /// property. If (which is default) is passed this will @@ -251,7 +249,6 @@ public static Transaction Create( IEnumerable actions, FungibleAssetValue? maxGasPrice = null, long? gasLimit = null, - IImmutableSet
? updatedAddresses = null, DateTimeOffset? timestamp = null) => Create( nonce, @@ -260,7 +257,6 @@ public static Transaction Create( new TxActionList(actions), maxGasPrice, gasLimit, - updatedAddresses, timestamp); /// @@ -310,7 +306,6 @@ private static Transaction Create( TxActionList actions, FungibleAssetValue? maxGasPrice = null, long? gasLimit = null, - IImmutableSet
? updatedAddresses = null, DateTimeOffset? timestamp = null) { if (privateKey is null) @@ -320,7 +315,6 @@ private static Transaction Create( var draftInvoice = new TxInvoice( genesisHash, - updatedAddresses ?? ImmutableHashSet
.Empty, timestamp ?? DateTimeOffset.UtcNow, actions, maxGasPrice, diff --git a/Libplanet/Blockchain/BlockChain.cs b/Libplanet/Blockchain/BlockChain.cs index 94d1d20bb99..c7f00c1f309 100644 --- a/Libplanet/Blockchain/BlockChain.cs +++ b/Libplanet/Blockchain/BlockChain.cs @@ -671,8 +671,6 @@ public long GetNextTxNonce(Address address) /// The maximum gas price this transaction can pay fee. /// The maximum amount of gas this transaction can consume. /// - /// es whose states affected by - /// . /// The time this is created and /// signed. /// A created new signed by the given @@ -682,7 +680,6 @@ public Transaction MakeTransaction( IEnumerable actions, FungibleAssetValue? maxGasPrice = null, long? gasLimit = null, - IImmutableSet
updatedAddresses = null, DateTimeOffset? timestamp = null) { timestamp = timestamp ?? DateTimeOffset.UtcNow; @@ -696,7 +693,6 @@ public Transaction MakeTransaction( actions.Select(x => x.PlainValue), maxGasPrice, gasLimit, - updatedAddresses, timestamp); StageTransaction(tx); return tx; From 7fd73275a52ea6d4676a16f72c6011bd80ed9b05 Mon Sep 17 00:00:00 2001 From: Say Cheong Date: Fri, 3 Nov 2023 17:55:04 +0900 Subject: [PATCH 4/4] Changelog --- CHANGES.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 32dc749fc72..bd6c1cd5ec7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,10 @@ To be released. ### Backward-incompatible API changes + - Removed `updatedAddresses` parameter from `BlockChain.MakeTransaction()` + [[#3480]] + - Removed `updatedAddresses` parameter from `Transaction.Create()`. [[#3480]] + - Removed `updatedAddresses` parameter from all `TxInvoice()`. [[#3480]] - Removed `Rehearsal` property from `IActionContext` and `ICommittedActionContext`. [[#3485]] - (Libplanet.Crypto) Removed `ToAddress()` extension method for @@ -31,6 +35,7 @@ To be released. ### CLI tools +[#3480]: https://github.com/planetarium/libplanet/pull/3480 [#3485]: https://github.com/planetarium/libplanet/pull/3485 [#3486]: https://github.com/planetarium/libplanet/pull/3486