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

RC1 to RC2 Comparison #5

Open
wants to merge 30 commits into
base: testnet-rc1-untouched
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b3be418
update to Neo v3.0.0-CI01234 (#538)
superboyiii Mar 6, 2021
209b674
public RpcServerSettings (#539)
devhawk Mar 7, 2021
0b69cf8
Fix State Autoverify when Oracle Service Unavailable (#540)
cloud8little Mar 8, 2021
68da90f
Integrate NeoFS into oracle module (#518)
doubiliu Mar 9, 2021
b54fb54
add settings to invokecontractverify (#546)
cloud8little Mar 10, 2021
f6dd422
Fix RpcNep17Tracker (#549)
erikzhang Mar 11, 2021
603ecec
Update Neo to 3.0.0-CI01239 (#551)
superboyiii Mar 12, 2021
adffb96
[DBFTPlugin] Dbft constructor (#545)
ZhangTao1596 Mar 15, 2021
89dcaa0
fix (#558)
Ashuaidehao Mar 15, 2021
a893ee0
Fix deploy contract in RpcClient (#559)
ProDog Mar 15, 2021
09ab00e
update policy api (#561)
ProDog Mar 15, 2021
67cabb8
[Oracle] Optimize neofs return type (#554)
ZhangTao1596 Mar 15, 2021
06d6cbd
[RpcServer] fix decimal (#562)
bettybao1209 Mar 15, 2021
93fb620
move Settings paramter to dbft plugin ctor (#563)
devhawk Mar 16, 2021
01c2e95
3.0.0-CI01246 (#565)
superboyiii Mar 17, 2021
1c24a3f
fix verify api (#564)
Ashuaidehao Mar 17, 2021
5bd92ab
RC1 (#566)
erikzhang Mar 17, 2021
e2b973f
update neofs-api (#567)
ZhangTao1596 Mar 18, 2021
b61ec2c
StatesDumper: fix bug with missing states dumps (#568)
AnnaShaleva Mar 23, 2021
9dc37f8
[RpcClient & OracleService] Fix ut and sync fs (#570)
bettybao1209 Mar 24, 2021
e77f074
fix null store when network not match (#571)
ZhangTao1596 Mar 24, 2021
86d0e4b
[StateService] Add sender check (#575)
ZhangTao1596 Mar 30, 2021
571fb1c
Fix (#574)
shargon Mar 31, 2021
736f5bc
Sync to Neov3.0.0-CI01257 (#576)
superboyiii Mar 31, 2021
a465c0a
Sync to Neo v3.0.0-CI01259 (#578)
superboyiii Apr 1, 2021
43f08ed
[OracleService] Update neofs api (#580)
ZhangTao1596 Apr 9, 2021
057ff46
Add user agent header (#581)
shargon Apr 12, 2021
4359882
Process iterator in RPC result (#583)
shargon Apr 20, 2021
fe8f26a
sync to Neo 3.0.0-CI01272 (#585)
ProDog Apr 29, 2021
900d0d9
[RC2] Update neo and neofs api (#588)
ZhangTao1596 May 1, 2021
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
4 changes: 2 additions & 2 deletions src/ApplicationLogs/LogReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected override void Configure()

protected override void OnSystemLoaded(NeoSystem system)
{
if (system.Settings.Magic != Settings.Default.Network) return;
if (system.Settings.Network != Settings.Default.Network) return;
RpcServerPlugin.RegisterMethods(this, Settings.Default.Network);
}

Expand Down Expand Up @@ -145,7 +145,7 @@ public static JObject BlockLogToJson(Block block, IReadOnlyList<Blockchain.Appli

void IPersistencePlugin.OnPersist(NeoSystem system, Block block, DataCache snapshot, IReadOnlyList<Blockchain.ApplicationExecuted> applicationExecutedList)
{
if (system.Settings.Magic != Settings.Default.Network) return;
if (system.Settings.Network != Settings.Default.Network) return;

WriteBatch writeBatch = new WriteBatch();

Expand Down
58 changes: 31 additions & 27 deletions src/DBFTPlugin/ConsensusContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ public class ConsensusContext : IDisposable, ISerializable
/// <summary>
/// Store all verified unsorted transactions' senders' fee currently in the consensus context.
/// </summary>
public TransactionVerificationContext VerificationContext = new TransactionVerificationContext();
public TransactionVerificationContext VerificationContext = new();

public SnapshotCache Snapshot { get; private set; }
private KeyPair keyPair;
private int _witnessSize;
private readonly NeoSystem neoSystem;
private readonly Settings dbftSettings;
private readonly Wallet wallet;
private readonly IStore store;
private Dictionary<UInt256, ConsensusMessage> cachedMessages;
Expand Down Expand Up @@ -94,17 +96,19 @@ public bool ValidatorsChanged

public int Size => throw new NotImplementedException();

public ConsensusContext(Wallet wallet, IStore store)
public ConsensusContext(NeoSystem neoSystem, Settings settings, Wallet wallet)
{
this.wallet = wallet;
this.store = store;
this.neoSystem = neoSystem;
this.dbftSettings = settings;
this.store = neoSystem.LoadStore(settings.RecoveryLogs);
}

public Block CreateBlock()
{
EnsureHeader();
Contract contract = Contract.CreateMultiSigContract(M, Validators);
ContractParametersContext sc = new ContractParametersContext(DBFTPlugin.System.StoreView, Block.Header);
ContractParametersContext sc = new ContractParametersContext(neoSystem.StoreView, Block.Header, dbftSettings.Network);
for (int i = 0, j = 0; i < Validators.Length && j < M; i++)
{
if (GetMessage(CommitPayloads[i])?.ViewNumber != ViewNumber) continue;
Expand Down Expand Up @@ -148,10 +152,10 @@ public void Deserialize(BinaryReader reader)
ViewNumber = reader.ReadByte();
TransactionHashes = reader.ReadSerializableArray<UInt256>(ushort.MaxValue);
Transaction[] transactions = reader.ReadSerializableArray<Transaction>(ushort.MaxValue);
PreparationPayloads = reader.ReadNullableArray<ExtensiblePayload>(DBFTPlugin.System.Settings.ValidatorsCount);
CommitPayloads = reader.ReadNullableArray<ExtensiblePayload>(DBFTPlugin.System.Settings.ValidatorsCount);
ChangeViewPayloads = reader.ReadNullableArray<ExtensiblePayload>(DBFTPlugin.System.Settings.ValidatorsCount);
LastChangeViewPayloads = reader.ReadNullableArray<ExtensiblePayload>(DBFTPlugin.System.Settings.ValidatorsCount);
PreparationPayloads = reader.ReadNullableArray<ExtensiblePayload>(neoSystem.Settings.ValidatorsCount);
CommitPayloads = reader.ReadNullableArray<ExtensiblePayload>(neoSystem.Settings.ValidatorsCount);
ChangeViewPayloads = reader.ReadNullableArray<ExtensiblePayload>(neoSystem.Settings.ValidatorsCount);
LastChangeViewPayloads = reader.ReadNullableArray<ExtensiblePayload>(neoSystem.Settings.ValidatorsCount);
if (TransactionHashes.Length == 0 && !RequestSentOrReceived)
TransactionHashes = null;
Transactions = transactions.Length == 0 && !RequestSentOrReceived ? null : transactions.ToDictionary(p => p.Hash);
Expand Down Expand Up @@ -265,7 +269,7 @@ public ExtensiblePayload MakeCommit()
{
return CommitPayloads[MyIndex] ?? (CommitPayloads[MyIndex] = MakeSignedPayload(new Commit
{
Signature = EnsureHeader().Sign(keyPair, DBFTPlugin.System.Settings.Magic)
Signature = EnsureHeader().Sign(keyPair, neoSystem.Settings.Network)
}));
}

Expand All @@ -284,7 +288,7 @@ private void SignPayload(ExtensiblePayload payload)
ContractParametersContext sc;
try
{
sc = new ContractParametersContext(DBFTPlugin.System.StoreView, payload);
sc = new ContractParametersContext(neoSystem.StoreView, payload, dbftSettings.Network);
wallet.Sign(sc);
}
catch (InvalidOperationException)
Expand Down Expand Up @@ -335,7 +339,7 @@ internal int GetExpectedBlockSizeWithoutTransactions(int expectedTransactions)
/// <param name="txs">Ordered transactions</param>
internal void EnsureMaxBlockLimitation(IEnumerable<Transaction> txs)
{
uint maxTransactionsPerBlock = DBFTPlugin.System.Settings.MaxTransactionsPerBlock;
uint maxTransactionsPerBlock = neoSystem.Settings.MaxTransactionsPerBlock;

// Limit Speaker proposal to the limit `MaxTransactionsPerBlock` or all available transactions of the mempool
txs = txs.Take((int)maxTransactionsPerBlock);
Expand All @@ -352,11 +356,11 @@ internal void EnsureMaxBlockLimitation(IEnumerable<Transaction> txs)
{
// Check if maximum block size has been already exceeded with the current selected set
blockSize += tx.Size;
if (blockSize > Settings.Default.MaxBlockSize) break;
if (blockSize > dbftSettings.MaxBlockSize) break;

// Check if maximum block system fee has been already exceeded with the current selected set
blockSystemFee += tx.SystemFee;
if (blockSystemFee > Settings.Default.MaxBlockSystemFee) break;
if (blockSystemFee > dbftSettings.MaxBlockSystemFee) break;

hashes.Add(tx.Hash);
Transactions.Add(tx.Hash, tx);
Expand All @@ -368,7 +372,7 @@ internal void EnsureMaxBlockLimitation(IEnumerable<Transaction> txs)

public ExtensiblePayload MakePrepareRequest()
{
EnsureMaxBlockLimitation(DBFTPlugin.System.MemPool.GetSortedVerifiedTransactions());
EnsureMaxBlockLimitation(neoSystem.MemPool.GetSortedVerifiedTransactions());
Block.Header.Timestamp = Math.Max(TimeProvider.Current.UtcNow.ToTimestampMS(), PrevHeader.Timestamp + 1);

return PreparationPayloads[MyIndex] = MakeSignedPayload(new PrepareRequest
Expand Down Expand Up @@ -403,16 +407,16 @@ public ExtensiblePayload MakeRecoveryMessage()
TransactionHashes = TransactionHashes
};
}
return MakeSignedPayload(new RecoveryMessage()
return MakeSignedPayload(new RecoveryMessage
{
ChangeViewMessages = LastChangeViewPayloads.Where(p => p != null).Select(p => GetChangeViewPayloadCompact(p)).Take(M).ToDictionary(p => (int)p.ValidatorIndex),
ChangeViewMessages = LastChangeViewPayloads.Where(p => p != null).Select(p => GetChangeViewPayloadCompact(p)).Take(M).ToDictionary(p => p.ValidatorIndex),
PrepareRequestMessage = prepareRequestMessage,
// We only need a PreparationHash set if we don't have the PrepareRequest information.
PreparationHash = TransactionHashes == null ? PreparationPayloads.Where(p => p != null).GroupBy(p => GetMessage<PrepareResponse>(p).PreparationHash, (k, g) => new { Hash = k, Count = g.Count() }).OrderByDescending(p => p.Count).Select(p => p.Hash).FirstOrDefault() : null,
PreparationMessages = PreparationPayloads.Where(p => p != null).Select(p => GetPreparationPayloadCompact(p)).ToDictionary(p => (int)p.ValidatorIndex),
PreparationMessages = PreparationPayloads.Where(p => p != null).Select(p => GetPreparationPayloadCompact(p)).ToDictionary(p => p.ValidatorIndex),
CommitMessages = CommitSent
? CommitPayloads.Where(p => p != null).Select(p => GetCommitPayloadCompact(p)).ToDictionary(p => (int)p.ValidatorIndex)
: new Dictionary<int, CommitPayloadCompact>()
? CommitPayloads.Where(p => p != null).Select(p => GetCommitPayloadCompact(p)).ToDictionary(p => p.ValidatorIndex)
: new Dictionary<byte, CommitPayloadCompact>()
});
}

Expand All @@ -429,7 +433,7 @@ public void Reset(byte viewNumber)
if (viewNumber == 0)
{
Snapshot?.Dispose();
Snapshot = DBFTPlugin.System.GetSnapshot();
Snapshot = neoSystem.GetSnapshot();
uint height = NativeContract.Ledger.CurrentIndex(Snapshot);
Block = new Block
{
Expand All @@ -438,17 +442,17 @@ public void Reset(byte viewNumber)
PrevHash = NativeContract.Ledger.CurrentHash(Snapshot),
Index = height + 1,
NextConsensus = Contract.GetBFTAddress(
NeoToken.ShouldRefreshCommittee(height + 1, DBFTPlugin.System.Settings.CommitteeMembersCount) ?
NativeContract.NEO.ComputeNextBlockValidators(Snapshot, DBFTPlugin.System.Settings) :
NativeContract.NEO.GetNextBlockValidators(Snapshot, DBFTPlugin.System.Settings.ValidatorsCount))
NeoToken.ShouldRefreshCommittee(height + 1, neoSystem.Settings.CommitteeMembersCount) ?
NativeContract.NEO.ComputeNextBlockValidators(Snapshot, neoSystem.Settings) :
NativeContract.NEO.GetNextBlockValidators(Snapshot, neoSystem.Settings.ValidatorsCount))
}
};
var pv = Validators;
Validators = NativeContract.NEO.GetNextBlockValidators(Snapshot, DBFTPlugin.System.Settings.ValidatorsCount);
Validators = NativeContract.NEO.GetNextBlockValidators(Snapshot, neoSystem.Settings.ValidatorsCount);
if (_witnessSize == 0 || (pv != null && pv.Length != Validators.Length))
{
// Compute the expected size of the witness
using (ScriptBuilder sb = new ScriptBuilder())
using (ScriptBuilder sb = new())
{
for (int x = 0; x < M; x++)
{
Expand Down Expand Up @@ -519,8 +523,8 @@ public void Serialize(BinaryWriter writer)
writer.Write(Block.PrimaryIndex);
writer.Write(Block.NextConsensus ?? UInt160.Zero);
writer.Write(ViewNumber);
writer.Write(TransactionHashes ?? new UInt256[0]);
writer.Write(Transactions?.Values.ToArray() ?? new Transaction[0]);
writer.Write(TransactionHashes ?? Array.Empty<UInt256>());
writer.Write(Transactions?.Values.ToArray() ?? Array.Empty<Transaction>());
writer.WriteNullableArray(PreparationPayloads);
writer.WriteNullableArray(CommitPayloads);
writer.WriteNullableArray(ChangeViewPayloads);
Expand Down
7 changes: 5 additions & 2 deletions src/DBFTPlugin/ConsensusMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public virtual void Deserialize(BinaryReader reader)
throw new FormatException();
BlockIndex = reader.ReadUInt32();
ValidatorIndex = reader.ReadByte();
if (ValidatorIndex >= DBFTPlugin.System.Settings.ValidatorsCount)
throw new FormatException();
ViewNumber = reader.ReadByte();
}

Expand All @@ -44,6 +42,11 @@ public static ConsensusMessage DeserializeFrom(byte[] data)
return (ConsensusMessage)data.AsSerializable(t);
}

public virtual bool Verify(ProtocolSettings protocolSettings)
{
return ValidatorIndex < protocolSettings.ValidatorsCount;
}

public virtual void Serialize(BinaryWriter writer)
{
writer.Write((byte)Type);
Expand Down
Loading