Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet format #1054

Merged
merged 2 commits into from
Aug 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void MaxSize_OK()
witness.Size.Should().Be(1003);
witness.InvocationScript.GetVarSize().Should().Be(653);
witness.VerificationScript.GetVarSize().Should().Be(350);

Assert.IsTrue(witness.Size <= 1024);

var copy = witness.ToArray().AsSerializable<Witness>();
Expand Down
3 changes: 2 additions & 1 deletion neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public class UT_NEP6Account
private static KeyPair keyPair;

[ClassInitialize]
public static void ClassSetup(TestContext context) {
public static void ClassSetup(TestContext context)
{
byte[] privateKey = { 0x01,0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01};
keyPair = new KeyPair(privateKey);
Expand Down
2 changes: 1 addition & 1 deletion neo/BigDecimal.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Numerics;

namespace Neo
Expand Down
2 changes: 1 addition & 1 deletion neo/Consensus/ChangeView.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.IO;
using System.IO;

namespace Neo.Consensus
{
Expand Down
2 changes: 1 addition & 1 deletion neo/Consensus/ChangeViewReason.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Neo.Consensus
namespace Neo.Consensus
{
public enum ChangeViewReason : byte
{
Expand Down
2 changes: 1 addition & 1 deletion neo/Consensus/Commit.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.IO;
using System.IO;

namespace Neo.Consensus
{
Expand Down
116 changes: 58 additions & 58 deletions neo/Consensus/ConsensusContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Neo.Persistence;
using Neo.SmartContract;
using Neo.SmartContract.Native;
using Neo.VM;
using Neo.VM;
using Neo.Wallets;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -39,11 +39,11 @@ internal class ConsensusContext : IDisposable, ISerializable

public Snapshot Snapshot { get; private set; }
private KeyPair keyPair;
private int _witnessSize;
private int _witnessSize;
private readonly Wallet wallet;
private readonly Store store;
private readonly Random random = new Random();

public int F => (Validators.Length - 1) / 3;
public int M => Validators.Length - F;
public bool IsPrimary => MyIndex == Block.ConsensusData.PrimaryIndex;
Expand Down Expand Up @@ -205,40 +205,40 @@ private void SignPayload(ConsensusPayload payload)
return;
}
payload.Witness = sc.GetWitnesses()[0];
}
}

/// <summary>
/// Return the expected block size
/// </summary>
internal int GetExpectedBlockSize()
{
return GetExpectedBlockSizeWithoutTransactions(Transactions.Count) + // Base size
Transactions.Values.Sum(u => u.Size); // Sum Txs
internal int GetExpectedBlockSize()
{
return GetExpectedBlockSizeWithoutTransactions(Transactions.Count) + // Base size
Transactions.Values.Sum(u => u.Size); // Sum Txs
}

/// <summary>
/// Return the expected block size without txs
/// </summary>
/// <param name="expectedTransactions">Expected transactions</param>
internal int GetExpectedBlockSizeWithoutTransactions(int expectedTransactions)
{
var blockSize =
// BlockBase
sizeof(uint) + //Version
UInt256.Length + //PrevHash
UInt256.Length + //MerkleRoot
sizeof(ulong) + //Timestamp
sizeof(uint) + //Index
UInt160.Length + //NextConsensus
1 + //
_witnessSize; //Witness
blockSize +=
// Block
Block.ConsensusData.Size + //ConsensusData
IO.Helper.GetVarSize(expectedTransactions + 1); //Transactions count
return blockSize;
/// <summary>
/// Return the expected block size without txs
/// </summary>
/// <param name="expectedTransactions">Expected transactions</param>
internal int GetExpectedBlockSizeWithoutTransactions(int expectedTransactions)
{
var blockSize =
// BlockBase
sizeof(uint) + //Version
UInt256.Length + //PrevHash
UInt256.Length + //MerkleRoot
sizeof(ulong) + //Timestamp
sizeof(uint) + //Index
UInt160.Length + //NextConsensus
1 + //
_witnessSize; //Witness

blockSize +=
// Block
Block.ConsensusData.Size + //ConsensusData
IO.Helper.GetVarSize(expectedTransactions + 1); //Transactions count

return blockSize;
}

/// <summary>
Expand All @@ -247,18 +247,18 @@ internal int GetExpectedBlockSizeWithoutTransactions(int expectedTransactions)
/// <param name="txs">Ordered transactions</param>
internal void EnsureMaxBlockSize(IEnumerable<Transaction> txs)
{
uint maxBlockSize = NativeContract.Policy.GetMaxBlockSize(Snapshot);
uint maxTransactionsPerBlock = NativeContract.Policy.GetMaxTransactionsPerBlock(Snapshot);
uint maxBlockSize = NativeContract.Policy.GetMaxBlockSize(Snapshot);
uint maxTransactionsPerBlock = NativeContract.Policy.GetMaxTransactionsPerBlock(Snapshot);

// Limit Speaker proposal to the limit `MaxTransactionsPerBlock` or all available transactions of the mempool
txs = txs.Take((int)maxTransactionsPerBlock);
List<UInt256> hashes = new List<UInt256>();
Transactions = new Dictionary<UInt256, Transaction>();
Block.Transactions = new Transaction[0];
// We need to know the expected block size
var blockSize = GetExpectedBlockSizeWithoutTransactions(txs.Count());
Block.Transactions = new Transaction[0];

// We need to know the expected block size

var blockSize = GetExpectedBlockSizeWithoutTransactions(txs.Count());

// Iterate transaction until reach the size

Expand All @@ -271,8 +271,8 @@ internal void EnsureMaxBlockSize(IEnumerable<Transaction> txs)
hashes.Add(tx.Hash);
Transactions.Add(tx.Hash, tx);
}
TransactionHashes = hashes.ToArray();

TransactionHashes = hashes.ToArray();
}

public ConsensusPayload MakePrepareRequest()
Expand All @@ -281,8 +281,8 @@ public ConsensusPayload MakePrepareRequest()
random.NextBytes(buffer);
Block.ConsensusData.Nonce = BitConverter.ToUInt64(buffer, 0);
EnsureMaxBlockSize(Blockchain.Singleton.MemPool.GetSortedVerifiedTransactions());
Block.Timestamp = Math.Max(TimeProvider.Current.UtcNow.ToTimestampMS(), PrevHeader.Timestamp + 1);
Block.Timestamp = Math.Max(TimeProvider.Current.UtcNow.ToTimestampMS(), PrevHeader.Timestamp + 1);

return PreparationPayloads[MyIndex] = MakeSignedPayload(new PrepareRequest
{
Timestamp = Block.Timestamp,
Expand Down Expand Up @@ -348,21 +348,21 @@ public void Reset(byte viewNumber)
};
var pv = Validators;
Validators = NativeContract.NEO.GetNextBlockValidators(Snapshot);
if (_witnessSize == 0 || (pv != null && pv.Length != Validators.Length))
{
// Compute the expected size of the witness
using (ScriptBuilder sb = new ScriptBuilder())
{
for (int x = 0; x < M; x++)
{
sb.EmitPush(new byte[64]);
}
_witnessSize = new Witness
{
InvocationScript = sb.ToArray(),
VerificationScript = Contract.CreateMultiSigRedeemScript(M, Validators)
}.Size;
}
if (_witnessSize == 0 || (pv != null && pv.Length != Validators.Length))
{
// Compute the expected size of the witness
using (ScriptBuilder sb = new ScriptBuilder())
{
for (int x = 0; x < M; x++)
{
sb.EmitPush(new byte[64]);
}
_witnessSize = new Witness
{
InvocationScript = sb.ToArray(),
VerificationScript = Contract.CreateMultiSigRedeemScript(M, Validators)
}.Size;
}
}
MyIndex = -1;
ChangeViewPayloads = new ConsensusPayload[Validators.Length];
Expand Down
2 changes: 1 addition & 1 deletion neo/Consensus/ConsensusMessage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Neo.IO;
using Neo.IO;
using Neo.IO.Caching;
using System;
using System.IO;
Expand Down
2 changes: 1 addition & 1 deletion neo/Consensus/ConsensusMessageType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Neo.IO.Caching;
using Neo.IO.Caching;

namespace Neo.Consensus
{
Expand Down
2 changes: 1 addition & 1 deletion neo/Consensus/ConsensusService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Akka.Actor;
using Akka.Actor;
using Akka.Configuration;
using Neo.Cryptography;
using Neo.IO;
Expand Down
2 changes: 1 addition & 1 deletion neo/Consensus/PrepareRequest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Neo.IO;
using Neo.IO;
using Neo.Network.P2P.Payloads;
using System;
using System.IO;
Expand Down
2 changes: 1 addition & 1 deletion neo/Consensus/PrepareResponse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Neo.IO;
using Neo.IO;
using System.IO;

namespace Neo.Consensus
Expand Down
2 changes: 1 addition & 1 deletion neo/Consensus/RecoveryMessage.ChangeViewPayloadCompact.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Neo.IO;
using Neo.IO;
using Neo.Network.P2P.Payloads;
using System.IO;

Expand Down
2 changes: 1 addition & 1 deletion neo/Consensus/RecoveryMessage.CommitPayloadCompact.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Neo.IO;
using Neo.IO;
using Neo.Network.P2P.Payloads;
using System.IO;

Expand Down
2 changes: 1 addition & 1 deletion neo/Consensus/RecoveryMessage.PreparationPayloadCompact.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Neo.IO;
using Neo.IO;
using Neo.Network.P2P.Payloads;
using System.IO;

Expand Down
2 changes: 1 addition & 1 deletion neo/Consensus/RecoveryMessage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Neo.IO;
using Neo.IO;
using Neo.Ledger;
using Neo.Network.P2P.Payloads;
using Neo.SmartContract;
Expand Down
2 changes: 1 addition & 1 deletion neo/Consensus/RecoveryRequest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.IO;
using System.IO;

namespace Neo.Consensus
{
Expand Down
2 changes: 1 addition & 1 deletion neo/Cryptography/Base58.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Numerics;
using System.Text;
Expand Down
2 changes: 1 addition & 1 deletion neo/Cryptography/BloomFilter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections;
using System.Collections;
using System.Linq;

namespace Neo.Cryptography
Expand Down
2 changes: 1 addition & 1 deletion neo/Cryptography/Crypto.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Security.Cryptography;

Expand Down
2 changes: 1 addition & 1 deletion neo/Cryptography/ECC/ECCurve.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Globalization;
using System.Globalization;
using System.Numerics;

namespace Neo.Cryptography.ECC
Expand Down
2 changes: 1 addition & 1 deletion neo/Cryptography/ECC/ECDsa.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography;
Expand Down
2 changes: 1 addition & 1 deletion neo/Cryptography/ECC/ECFieldElement.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Numerics;

Expand Down
2 changes: 1 addition & 1 deletion neo/Cryptography/ECC/ECPoint.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Neo.IO;
using Neo.IO;
using System;
using System.IO;
using System.Linq;
Expand Down
2 changes: 1 addition & 1 deletion neo/Cryptography/Helper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Neo.IO;
using Neo.IO;
using Neo.Network.P2P.Payloads;
using System;
using System.Collections.Generic;
Expand Down
2 changes: 1 addition & 1 deletion neo/Cryptography/MerkleTree.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
Expand Down
2 changes: 1 addition & 1 deletion neo/Cryptography/MerkleTreeNode.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Neo.Cryptography
namespace Neo.Cryptography
{
internal class MerkleTreeNode
{
Expand Down
2 changes: 1 addition & 1 deletion neo/Cryptography/Murmur3.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;

Expand Down
2 changes: 1 addition & 1 deletion neo/Cryptography/RIPEMD160Managed.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !NET47
#if !NET47
using System;
using System.Runtime.InteropServices;
using System.Security;
Expand Down
2 changes: 1 addition & 1 deletion neo/Cryptography/SCrypt.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Security.Cryptography;

namespace Neo.Cryptography
Expand Down
2 changes: 1 addition & 1 deletion neo/Helper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration;
using Neo.Plugins;
using System;
using System.Collections.Generic;
Expand Down
2 changes: 1 addition & 1 deletion neo/IO/Actors/Idle.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Neo.IO.Actors
namespace Neo.IO.Actors
{
internal sealed class Idle
{
Expand Down
2 changes: 1 addition & 1 deletion neo/IO/Actors/PriorityMailbox.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Akka.Actor;
using Akka.Actor;
using Akka.Configuration;
using Akka.Dispatch;
using Akka.Dispatch.MessageQueues;
Expand Down
2 changes: 1 addition & 1 deletion neo/IO/Actors/PriorityMessageQueue.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Akka.Actor;
using Akka.Actor;
using Akka.Dispatch;
using Akka.Dispatch.MessageQueues;
using System;
Expand Down
2 changes: 1 addition & 1 deletion neo/IO/ByteArrayComparer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;

namespace Neo.IO
Expand Down
2 changes: 1 addition & 1 deletion neo/IO/Caching/Cache.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
Expand Down
Loading