Skip to content

Commit

Permalink
Update (#1)
Browse files Browse the repository at this point in the history
* Handles escape characters in JSON

*  Pass ApplicationExecution to IPersistencePlugin (neo-project#531)

* Update dependencies: (neo-project#532)

- Akka 1.3.11
- Microsoft.AspNetCore.ResponseCompression 2.2.0
- Microsoft.AspNetCore.Server.Kestrel 2.2.0
- Microsoft.AspNetCore.Server.Kestrel.Https 2.2.0
- Microsoft.AspNetCore.WebSockets 2.2.0
- Microsoft.EntityFrameworkCore.Sqlite 2.2.0
- Microsoft.Extensions.Configuration.Json 2.2.0

* change version to v2.9.4

* Updating Unknown to Policy Fail (neo-project#533)

* Fix a dead lock in `WalletIndexer`

* Downgrade Sqlite to 2.1.4 (neo-project#535)

* RPC call gettransactionheight (neo-project#541)

* getrawtransactionheight

Nowadays two calls are need to get a transaction height, `getrawtransaction` with `verbose` and then use the `blockhash`.
Other option is to use `confirmations`, but it can be misleading.

* Minnor fix

* Shargon's tip

* modified

* Allow to use the wallet inside a RPC plugin (neo-project#536)

* Improve Large MemoryPool Performance - Sort + intelligent TX reverification (neo-project#500)

Improve Large MemoryPool Performance - Sort + intelligent TX reverification (neo-project#500)

* Keep both verified and unverified (previously verified) transactions in sorted trees so ejecting transactions above the pool size is a low latency operation.
* Re-verify unverified transactions when Blockchain actor is idle.
* Don't re-verify transactions needlessly when not at the tip of the chain.
* Support passing a flag to `getrawmempool` to retrieve both verified and unverified TX hashes.
* Support MaxTransactionsPerBlock and MaxFreeTransactionsPerBlock from Policy plugins.
* Rebroadcast re-verified transactions if it has been a while since last broadcast (high priority transactions are rebroadcast more frequently than low priority transactions.

* Policy filter GetRelayResult message (neo-project#543)

* Policy filter GetRelayResult message

* adding fixed numbering for return codes

* Removed enum fixed values

* Add some initial MemoryPool unit tests. Fix bug when Persisting the GenesisBlock (neo-project#549)

* More MemoryPool Unit Tests. Improve Re-broadcast back-off to an increasing linear formula. (neo-project#554)

* Ensuring Object Reference check of SortedSets for speed-up (neo-project#557)

* Minor comments update on Mempool class (neo-project#556)

* Update MemoryPool Unit Test to add random fees to Mock Transactions (neo-project#558)

* Add Unit Test for MemoryPool sort order. Fixed sort order to return descending. (neo-project#559)

* Add unit test to verify memory pool sort order and reverification order. Fixed sort order bug.

* VerifyCanTransactionFitInPool works as intended. Also inadvertantly verified GetLowestFeeTransaction() works.

* Benchmark structure for UInt classes (neo-project#553)

* basic benchmark structure for UInt classes

* commented code2 from lights for now

* updated tests. all seem correct now

* Switch to using a benchmark method taking a method delegate to benchmark.

* Make pass.

* 1 million iterations.

* Switch to ulong for the 4th option, and it is still the same speed.

* fix test data for 50% equal data

* make test pass

* neo.UnitTests/UT_UIntBenchmarks.cs

* neo.UnitTests/UT_UIntBenchmarks.cs

* Base 20 - UInt160 tests

* neo.UnitTests/UT_UIntBenchmarks.cs

* inlined 160

* complete tests with UInt256 and UInt160

* neo.UnitTests/UT_UIntBenchmarks.cs

* Lights division calculation

* Treat lower hashes as higher priority. Fix MemoryPool UT for Hash order. (neo-project#563)

* Treat lower hashes as higher priority. 
* Fix MemoryPool UT for Hash order.
* Renaming Trasanction in PoolItem for clarity.

* Make PoolItem independent and add PoolItem tests (neo-project#562)

* make poolitem independent

* Merging

* Multiply by -1

* Fix other

* Fix Tx

* Removing -1 extra multiplication

* Fix

* make PoolItem internal and added test class

* Update PoolItem.cs

* added comments for PoolItem variables

* getting time from TimeProvider to allow testing

* basic test

* reset time provider

* Add Hash comparison

* Adding time provider again and equals

* Fix arithmetic

* Comment on PoolItem

* Update PoolItem.cs

* protecting tests against TimeProvider changes on fails

* reusing setup part

* fixed serialization properties

* Improve generation of creating mock DateTime values. Implement hash comparison tests.

* Adjust comment.

* Treat Claim transactions as the highest low priority transactions. (neo-project#565)

* Allow persistence plugins to commit as a final step. (neo-project#568)

* Allow persistence plugins to commit as a final step.

* Plugins commit before core commits, once all plugins have handled initial work OnPersist.

* Allow PersistencePlugin to determine whether to crash if commit fails.

* Add ShouldThrowExceptionFromCommit method to IPersistencePlugin.

* Throw all commit exceptions that should be thrown in an AggregateException.

* Add a Plugin type for observing transactions added or removed from the MemoryPool. (neo-project#580)

* Correctly handle conversions between JSON objects (neo-project#586)

* Fix neo-project/neo-node#297 (neo-project#587)

* Replace new JArray with .ToArray (AccountState) (neo-project#581)

* Ensure `LocalNode` to be stoped before shutting down the `NeoSystem`
  • Loading branch information
txhsl authored Feb 25, 2019
1 parent a8fd76b commit 2b1c266
Show file tree
Hide file tree
Showing 30 changed files with 1,702 additions and 349 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dist: trusty
osx_image: xcode9.1

mono: none
dotnet: 2.0.0
dotnet: 2.1.502

before_install:
- cd neo.UnitTests
Expand Down
16 changes: 14 additions & 2 deletions neo.UnitTests/TestDataCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ public class TestDataCache<TKey, TValue> : DataCache<TKey, TValue>
where TKey : IEquatable<TKey>, ISerializable
where TValue : class, ICloneable<TValue>, ISerializable, new()
{
private readonly TValue _defaultValue;

public TestDataCache()
{
_defaultValue = null;
}

public TestDataCache(TValue defaultValue)
{
this._defaultValue = defaultValue;
}
public override void DeleteInternal(TKey key)
{
}
Expand All @@ -25,12 +36,13 @@ protected override IEnumerable<KeyValuePair<TKey, TValue>> FindInternal(byte[] k

protected override TValue GetInternal(TKey key)
{
throw new NotImplementedException();
if (_defaultValue == null) throw new NotImplementedException();
return _defaultValue;
}

protected override TValue TryGetInternal(TKey key)
{
return null;
return _defaultValue;
}

protected override void UpdateInternal(TKey key, TValue value)
Expand Down
401 changes: 401 additions & 0 deletions neo.UnitTests/UT_MemoryPool.cs

Large diffs are not rendered by default.

178 changes: 178 additions & 0 deletions neo.UnitTests/UT_PoolItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Neo.Ledger;
using FluentAssertions;
using Neo.Network.P2P.Payloads;

namespace Neo.UnitTests
{
[TestClass]
public class UT_PoolItem
{
//private PoolItem uut;
private static readonly Random TestRandom = new Random(1337); // use fixed seed for guaranteed determinism

[TestInitialize]
public void TestSetup()
{
var timeValues = new[] {
new DateTime(1968, 06, 01, 0, 0, 1, DateTimeKind.Utc),
};

var timeMock = new Mock<TimeProvider>();
timeMock.SetupGet(tp => tp.UtcNow).Returns(() => timeValues[0])
.Callback(() => timeValues[0] = timeValues[0].Add(TimeSpan.FromSeconds(1)));
TimeProvider.Current = timeMock.Object;
}

[TestCleanup]
public void TestCleanup()
{
// important to leave TimeProvider correct
TimeProvider.ResetToDefault();
}

[TestMethod]
public void PoolItem_CompareTo_ClaimTx()
{
var tx1 = GenerateClaimTx();
// Non-free low-priority transaction
var tx2 = MockGenerateInvocationTx(new Fixed8(99999), 50).Object;

var poolItem1 = new PoolItem(tx1);
var poolItem2 = new PoolItem(tx2);
poolItem1.CompareTo(poolItem2).Should().Be(1);
poolItem2.CompareTo(poolItem1).Should().Be(-1);
}

[TestMethod]
public void PoolItem_CompareTo_Fee()
{
int size1 = 50;
int netFeeSatoshi1 = 1;
var tx1 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshi1), size1);
int size2 = 50;
int netFeeSatoshi2 = 2;
var tx2 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshi2), size2);

PoolItem pitem1 = new PoolItem(tx1.Object);
PoolItem pitem2 = new PoolItem(tx2.Object);

Console.WriteLine($"item1 time {pitem1.Timestamp} item2 time {pitem2.Timestamp}");
// pitem1 < pitem2 (fee) => -1
pitem1.CompareTo(pitem2).Should().Be(-1);
// pitem2 > pitem1 (fee) => 1
pitem2.CompareTo(pitem1).Should().Be(1);
}

[TestMethod]
public void PoolItem_CompareTo_Hash()
{
int sizeFixed = 50;
int netFeeSatoshiFixed = 1;

for (int testRuns = 0; testRuns < 30; testRuns++)
{
var tx1 = GenerateMockTxWithFirstByteOfHashGreaterThanOrEqualTo(0x80, new Fixed8(netFeeSatoshiFixed), sizeFixed);
var tx2 = GenerateMockTxWithFirstByteOfHashLessThanOrEqualTo(0x79,new Fixed8(netFeeSatoshiFixed), sizeFixed);

PoolItem pitem1 = new PoolItem(tx1.Object);
PoolItem pitem2 = new PoolItem(tx2.Object);

// pitem2 < pitem1 (fee) => -1
pitem2.CompareTo(pitem1).Should().Be(-1);

// pitem1 > pitem2 (fee) => 1
pitem1.CompareTo(pitem2).Should().Be(1);
}

// equal hashes should be equal
var tx3 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshiFixed), sizeFixed, new byte[] {0x13, 0x37});
var tx4 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshiFixed), sizeFixed, new byte[] {0x13, 0x37});
PoolItem pitem3 = new PoolItem(tx3.Object);
PoolItem pitem4 = new PoolItem(tx4.Object);

pitem3.CompareTo(pitem4).Should().Be(0);
pitem4.CompareTo(pitem3).Should().Be(0);
}

[TestMethod]
public void PoolItem_CompareTo_Equals()
{
int sizeFixed = 500;
int netFeeSatoshiFixed = 10;
var tx1 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshiFixed), sizeFixed, new byte[] {0x13, 0x37});
var tx2 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshiFixed), sizeFixed, new byte[] {0x13, 0x37});

PoolItem pitem1 = new PoolItem(tx1.Object);
PoolItem pitem2 = new PoolItem(tx2.Object);

// pitem1 == pitem2 (fee) => 0
pitem1.CompareTo(pitem2).Should().Be(0);
pitem2.CompareTo(pitem1).Should().Be(0);
}

public Mock<InvocationTransaction> GenerateMockTxWithFirstByteOfHashGreaterThanOrEqualTo(byte firstHashByte, Fixed8 networkFee, int size)
{
Mock<InvocationTransaction> mockTx;
do
{
mockTx = MockGenerateInvocationTx(networkFee, size);
} while (mockTx.Object.Hash >= new UInt256(TestUtils.GetByteArray(32, firstHashByte)));

return mockTx;
}

public Mock<InvocationTransaction> GenerateMockTxWithFirstByteOfHashLessThanOrEqualTo(byte firstHashByte, Fixed8 networkFee, int size)
{
Mock<InvocationTransaction> mockTx;
do
{
mockTx = MockGenerateInvocationTx(networkFee, size);
} while (mockTx.Object.Hash <= new UInt256(TestUtils.GetByteArray(32, firstHashByte)));

return mockTx;
}

public static Transaction GenerateClaimTx()
{
var mockTx = new Mock<ClaimTransaction>();
mockTx.CallBase = true;
mockTx.SetupGet(mr => mr.NetworkFee).Returns(Fixed8.Zero);
mockTx.SetupGet(mr => mr.Size).Returns(50);
var tx = mockTx.Object;
tx.Attributes = new TransactionAttribute[0];
tx.Inputs = new CoinReference[0];
tx.Outputs = new TransactionOutput[0];
tx.Witnesses = new Witness[0];
return mockTx.Object;
}

// Generate Mock InvocationTransaction with different sizes and prices
public static Mock<InvocationTransaction> MockGenerateInvocationTx(Fixed8 networkFee, int size, byte[] overrideScriptBytes=null)
{
var mockTx = new Mock<InvocationTransaction>();
mockTx.CallBase = true;
mockTx.SetupGet(mr => mr.NetworkFee).Returns(networkFee);
mockTx.SetupGet(mr => mr.Size).Returns(size);

var tx = mockTx.Object;
// use random bytes in the script to get a different hash since we cannot mock the Hash
byte[] randomBytes;
if (overrideScriptBytes != null)
randomBytes = overrideScriptBytes;
else
{
randomBytes = new byte[16];
TestRandom.NextBytes(randomBytes);
}
tx.Script = randomBytes;
tx.Attributes = new TransactionAttribute[0];
tx.Inputs = new CoinReference[0];
tx.Outputs = new TransactionOutput[0];
tx.Witnesses = new Witness[0];
return mockTx;
}
}
}
Loading

0 comments on commit 2b1c266

Please sign in to comment.