Skip to content

Commit

Permalink
Cleanup useless things
Browse files Browse the repository at this point in the history
  • Loading branch information
moreal committed Sep 4, 2019
1 parent f216c8d commit b156211
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 78 deletions.
8 changes: 0 additions & 8 deletions CHANGES.md
Expand Up @@ -59,9 +59,6 @@ To be released.
both a `Block<T>.Hash` and a `Transaction<T>.Id`, so that signers cannot
predict the order of transactions in a block before it's mined.
[[#244], [#355]]
- `TxId` class became to implement `IComparable<TxId>` and
`IComparable` interfaces. [[#244], [#355]]
- Added `InvalidBlockTransactionsException` class. [[#244], [#355]]

### Behavioral changes

Expand All @@ -80,9 +77,6 @@ To be released.
connected to each peer. [[#353]]
- `TxId`s and `Block`s are now broadcasted to selected peers from routing table of
the host peer. [[#353]]
- `Block<T>.Mine(long, long, Address, HashDigest<SHA256>?, DateTimeOffset,
IEnumerable<Transaction<T>>)` became to order `Block<T>.Transactions` by
their `Id`. [[#244], [#355]]

### Bug fixes

Expand Down Expand Up @@ -139,8 +133,6 @@ Released on August 28, 2019.
- Fixed a bug that unnecessarily received all blocks in multiple miner
situations. [[#457], [#468]]

[#420]: https://github.com/planetarium/libplanet/pull/420
[#450]: https://github.com/planetarium/libplanet/pull/450
[#454]: https://github.com/planetarium/libplanet/issues/454
[#457]: https://github.com/planetarium/libplanet/issues/457
[#466]: https://github.com/planetarium/libplanet/pull/466
Expand Down
2 changes: 1 addition & 1 deletion Libplanet.Tests/Blocks/BlockTest.cs
Expand Up @@ -269,7 +269,7 @@ public void EvaluateActionsPerTx()
0,
_fx.TxFixture.PrivateKey2,
new[] { MakeAction(addresses[3], 'E') },
timestamp: DateTimeOffset.MinValue.AddSeconds(3)
timestamp: DateTimeOffset.MinValue.AddSeconds(1)
),
Transaction<DumbAction>.Create(
0,
Expand Down
2 changes: 0 additions & 2 deletions Libplanet.Tests/TestUtils.cs
Expand Up @@ -107,8 +107,6 @@ internal static Block<T> MineGenesis<T>(Address? miner = null)
txs = new List<Transaction<T>>();
}

txs = txs.OrderBy(tx => tx.Id);

long index = previousBlock.Index + 1;
HashDigest<SHA256> previousHash = previousBlock.Hash;
DateTimeOffset timestamp = previousBlock.Timestamp.AddDays(1);
Expand Down
4 changes: 1 addition & 3 deletions Libplanet/Blockchain/BlockChain.cs
Expand Up @@ -546,11 +546,9 @@ bool renderActions
}

HashDigest<SHA256>? tip = Store.IndexBlockHash(Id, -1);
IEnumerable<Transaction<T>> transactions =
block.Transactions.OrderBy(tx => tx.Nonce);

var nonceDeltas = new Dictionary<Address, long>();
foreach (Transaction<T> tx1 in transactions)
foreach (Transaction<T> tx1 in block.Transactions)
{
Address txSigner = tx1.Signer;
nonceDeltas.TryGetValue(txSigner, out var nonceDelta);
Expand Down
22 changes: 2 additions & 20 deletions Libplanet/Blocks/Block.cs
Expand Up @@ -109,9 +109,7 @@ private Block(RawBlock rb)
DateTimeOffset timestamp,
IEnumerable<Transaction<T>> transactions)
{
ImmutableArray<Transaction<T>> orderedTxs =
transactions.OrderBy(tx => tx.Id).ToImmutableArray();

Transaction<T>[] orderedTxs = transactions.OrderBy(tx => tx.Nonce).ToArray();
Block<T> MakeBlock(Nonce n) => new Block<T>(
index,
difficulty,
Expand Down Expand Up @@ -400,22 +398,6 @@ internal void Validate(DateTimeOffset currentTime)
);
}

if (Transactions.Any())
{
TxId beforeTxId = Transactions.First().Id;
foreach (Transaction<T> tx in Transactions.Skip(1))
{
if (beforeTxId.CompareTo(tx.Id) > 0)
{
throw new InvalidBlockTransactionsException(
$"transactions of {Hash} aren't sorted by Transaction<T>.Id"
);
}

beforeTxId = tx.Id;
}
}

foreach (Transaction<T> tx in Transactions)
{
tx.Validate();
Expand All @@ -428,7 +410,7 @@ bool includeTransactionData
)
{
IEnumerable transactions =
Transactions.OrderBy(tx => tx.Id).Select(
Transactions.Select(
tx => includeTransactionData ?
tx.ToRawTransaction(true) as object :
tx.Id.ToByteArray() as object
Expand Down
13 changes: 0 additions & 13 deletions Libplanet/Blocks/InvalidBlockTransactionsException.cs

This file was deleted.

32 changes: 1 addition & 31 deletions Libplanet/Tx/TxId.cs
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.Contracts;
using System.Linq;
Expand All @@ -19,7 +18,7 @@ namespace Libplanet.Tx
/// <seealso cref="Transaction{T}.Id"/>
[Serializable]
[Equals]
public struct TxId : ISerializable, IComparable<TxId>, IComparable
public struct TxId : ISerializable
{
/// <summary>
/// The <see cref="byte"/>s size that each <see cref="TxId"/> takes.
Expand Down Expand Up @@ -116,35 +115,6 @@ public ImmutableArray<byte> ByteArray
[Pure]
public override string ToString() => ToHex();

public int CompareTo(TxId other)
{
for (int i = 0; i < Size; ++i)
{
int cmp = ByteArray[i].CompareTo(other.ByteArray[i]);
if (cmp != 0)
{
return cmp;
}
}

return 0;
}

public int CompareTo(object obj)
{
if (obj is TxId other)
{
return ((IComparable<TxId>)this).CompareTo(other);
}

if (obj is null)
{
throw new ArgumentNullException(nameof(obj));
}

throw new ArgumentException(nameof(obj));
}

/// <inheritdoc />
public void GetObjectData(
SerializationInfo info,
Expand Down

0 comments on commit b156211

Please sign in to comment.