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

Set max block size #953

Merged
merged 54 commits into from
Aug 20, 2019
Merged
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
dfa6dc6
Draft
shargon Jul 24, 2019
d1616d8
Take into account p2p max payload
shargon Jul 24, 2019
89fe5b0
Move max allowed to policy
shargon Jul 25, 2019
0ddf1e9
Check block size on prepResponse
shargon Jul 25, 2019
5d97f71
Change reason
shargon Jul 25, 2019
f622e57
Prevent overflow
shargon Jul 25, 2019
618d2d9
Merge branch 'master' into max-block-size
shargon Jul 25, 2019
4a111bc
Optimization
shargon Jul 26, 2019
a013394
Reduce the length of the array
shargon Jul 26, 2019
94a29dc
Organizing consensus code
vncoelho Jul 30, 2019
dba9733
Revert "Organizing consensus code"
vncoelho Jul 30, 2019
b38c9a7
Remove Policy UT
shargon Jul 31, 2019
643af4d
Merge branch 'master' into max-block-size
shargon Jul 31, 2019
b05fc39
Resolve Policy conflicts
shargon Jul 31, 2019
2d54874
prepare unit test
shargon Jul 31, 2019
3c35703
Small unit test
shargon Jul 31, 2019
63d64c8
More ut
shargon Jul 31, 2019
9419e4a
Add one check
shargon Jul 31, 2019
138a342
Clean using
shargon Jul 31, 2019
5d4ebe8
Organizing consensus and comments
vncoelho Jul 31, 2019
aa6cbee
Split unit test
shargon Aug 2, 2019
bad503f
Merge branch 'master' into max-block-size
shargon Aug 2, 2019
a942fc5
UT check block size
shargon Aug 2, 2019
6821ee5
Clean
shargon Aug 2, 2019
f9dcbeb
Expected witness size
shargon Aug 2, 2019
5ad4500
optimize
erikzhang Aug 5, 2019
33b68c9
Merge branch 'master' into max-block-size
shargon Aug 5, 2019
7209503
Remove fakeWitness
shargon Aug 5, 2019
165fe96
Format comments
shargon Aug 5, 2019
94b8fc9
rename var
shargon Aug 5, 2019
7a26d2e
Add (..)
shargon Aug 5, 2019
2ef7c2f
Remove SetKey method
shargon Aug 6, 2019
1847366
Merge branch 'master' into max-block-size
shargon Aug 6, 2019
7a799db
Centralize expected block size
shargon Aug 6, 2019
13ccd2a
Merge remote-tracking branch 'shargon/max-block-size' into max-block-…
shargon Aug 6, 2019
1dca8d5
Optimize
shargon Aug 6, 2019
dbda619
Fix
shargon Aug 6, 2019
8d385a8
Add one test
shargon Aug 6, 2019
754541a
Merge branch 'master' into max-block-size
lock9 Aug 7, 2019
accbf72
Optimize `EnsureMaxBlockSize()`
erikzhang Aug 8, 2019
b8e80b0
Fix unit tests
shargon Aug 8, 2019
44de151
Rename
shargon Aug 8, 2019
fa5b743
Indent
shargon Aug 8, 2019
a5b1eb3
Merge branch 'master' into max-block-size
erikzhang Aug 9, 2019
f98a40a
Merge branch 'master' into max-block-size
shargon Aug 12, 2019
9aa49b4
Vitor suggestion
shargon Aug 12, 2019
dc9fd12
Merge with Scoped signatures
shargon Aug 12, 2019
e134881
Remove extra line
vncoelho Aug 12, 2019
a9282c0
Revert "Remove extra line"
vncoelho Aug 12, 2019
c7a063e
Remove extra line
vncoelho Aug 12, 2019
863611c
Merge branch 'master' into max-block-size
shargon Aug 12, 2019
396bd1a
Merge branch 'master' into max-block-size
igormcoelho Aug 16, 2019
7b5ebc1
Merge branch 'master' into max-block-size
vncoelho Aug 16, 2019
f42a7c9
Merge branch 'master' into max-block-size
shargon Aug 20, 2019
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
Prev Previous commit
Next Next commit
Optimize EnsureMaxBlockSize()
  • Loading branch information
erikzhang committed Aug 8, 2019
commit accbf72476ed68ac3a6ca43388225770f19c8988
18 changes: 7 additions & 11 deletions neo/Consensus/ConsensusContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,12 @@ internal int GetExpectedBlockSize(bool computeTransactionSize)
/// <param name="txs">Ordered transactions</param>
internal void EnsureMaxBlockSize(IEnumerable<Transaction> txs)
{
shargon marked this conversation as resolved.
Show resolved Hide resolved
var transactions = txs.ToList();
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
TransactionHashes = new UInt256[Math.Min(transactions.Count, NativeContract.Policy.GetMaxTransactionsPerBlock(Snapshot))];
txs = txs.Take((int)maxTransactionsPerBlock);
List<UInt256> hashes = new List<UInt256>();
Transactions = new Dictionary<UInt256, Transaction>();
shargon marked this conversation as resolved.
Show resolved Hide resolved
Block.Transactions = new Transaction[0];

Expand All @@ -259,22 +260,17 @@ internal void EnsureMaxBlockSize(IEnumerable<Transaction> txs)

// Iterate transaction until reach the size

for (int x = 0, max = TransactionHashes.Length; x < max; x++)
foreach (Transaction tx in txs)
{
var tx = transactions[x];

// Check if maximum block size has been already exceeded with the current selected set
blockSize += tx.Size;
if (blockSize > maxBlockSize) break;

TransactionHashes[x] = tx.Hash;
hashes.Add(tx.Hash);
Transactions.Add(tx.Hash, tx);
}

// Truncate null values [Tx1,Tx2,null,null,null]

if (TransactionHashes.Length > Transactions.Count)
Array.Resize(ref TransactionHashes, Transactions.Count);

TransactionHashes = hashes.ToArray();
}

public ConsensusPayload MakePrepareRequest()
Expand Down