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

Feature chain context #98

Merged
merged 52 commits into from
Apr 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
69efb2b
Merge pull request #17 from AElfProject/dev
shiwk Mar 28, 2018
bcff1f9
remove account and account manager
shiwk Mar 28, 2018
b16a871
modify structures without account
shiwk Mar 28, 2018
dd5de05
implement IChain
shiwk Mar 29, 2018
f299c4d
autofac register
shiwk Mar 29, 2018
4a77918
chain creation
shiwk Mar 29, 2018
c8322ed
chain test cases
shiwk Mar 29, 2018
42ea717
Merge pull request #18 from AElfProject/feature-protobuf-integration-…
shiwk Mar 29, 2018
2004b06
Merge branch 'feature-chain-context-0329' of https://github.com/shiwk…
shiwk Mar 29, 2018
640c38d
add smartcontract manager
shiwk Mar 31, 2018
d2b8eb8
autofac module register
shiwk Mar 31, 2018
38a9103
add smartcontract runner
shiwk Mar 31, 2018
c92db64
few modifications
shiwk Mar 31, 2018
c74a10d
chain test cases
shiwk Mar 31, 2018
7da45c3
add index in block header
shiwk Mar 31, 2018
bd215ca
add SmartContract implemention
shiwk Mar 31, 2018
84f1402
implement SmartContractFactory
shiwk Mar 31, 2018
f5484be
few modifications
shiwk Mar 31, 2018
0eadb96
account context test
shiwk Apr 2, 2018
53c2096
SmartContractRegisteration storage
shiwk Apr 2, 2018
2708810
smart contract zero runner
shiwk Apr 2, 2018
2ac74f1
smart contract manager
shiwk Apr 2, 2018
5551e66
modify chain context service
shiwk Apr 2, 2018
f59f51e
add block test
shiwk Apr 4, 2018
9d08d8c
modify block structure
shiwk Apr 4, 2018
95eda01
modify chain test cases
shiwk Apr 4, 2018
5c7d56c
modify Autofac register
shiwk Apr 4, 2018
ed756c3
readme
shiwk Apr 4, 2018
0ca8960
Merge pull request #20 from AElfProject/dev
shiwk Apr 8, 2018
fbae025
Merge branch 'feature-chain-context-0408' of https://github.com/shiwk…
shiwk Apr 8, 2018
8e21184
fix errors
shiwk Apr 10, 2018
6c4e42b
transaction pool
shiwk Apr 11, 2018
c07d5f5
transaction pool configuration
shiwk Apr 11, 2018
c44d1ce
add transaction to pool
shiwk Apr 12, 2018
b668636
add TxPoolManager
shiwk Apr 12, 2018
9aedafc
remove IHash
shiwk Apr 12, 2018
7089e58
ValidateTx and AddTx
shiwk Apr 12, 2018
c384890
add RemoveTx
shiwk Apr 13, 2018
6dc1d4e
improve AddTx
shiwk Apr 13, 2018
883284c
modify tx pool config
shiwk Apr 13, 2018
797e525
add Promote method
shiwk Apr 13, 2018
0128db1
GetPoolSize method
shiwk Apr 13, 2018
0c3cc92
add concurrent collection
shiwk Apr 14, 2018
2b8d979
Merge branch 'dev' of https://github.com/AElfProject/AElf into featur…
shiwk Apr 14, 2018
35903f6
fix some bugs
shiwk Apr 14, 2018
a0a4589
fix bug
shiwk Apr 14, 2018
038d807
modify unittest
shiwk Apr 14, 2018
46a5911
few modifications
shiwk Apr 14, 2018
50ae105
remove files
shiwk Apr 14, 2018
8596bd9
merge conflicts
shiwk Apr 14, 2018
fb739db
add sm registration store
shiwk Apr 14, 2018
8c7bad9
merge conflicts
shiwk Apr 14, 2018
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
3 changes: 1 addition & 2 deletions AElf.Kernel.Modules.AutofacModule/Module.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Autofac;
using Autofac;

namespace AElf.Kernel.Modules.AutofacModule
{
Expand Down
33 changes: 33 additions & 0 deletions AElf.Kernel.Tests/AccountContextTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Xunit;
using Xunit.Frameworks.Autofac;

namespace AElf.Kernel.Tests
{
[UseAutofacTestFramework]
public class AccountContextTest
{
private readonly AccountContextService _accountContextService;

public AccountContextTest(AccountContextService accountContextService)
{
_accountContextService = accountContextService;
}

[Fact]
public void GetAccountContextTest()
{
var chainId = Hash.Generate();
var accountId = Hash.Generate();

var context1 = _accountContextService.GetAccountDataContext(accountId, chainId);
var context2 = _accountContextService.GetAccountDataContext(accountId, chainId);
Assert.Equal(context1, context2);

context1.IncreasementId++;
var context3 = _accountContextService.GetAccountDataContext(accountId, chainId);
Assert.Equal(context1, context3);
Assert.Equal(context3.IncreasementId, (ulong)1);
}

}
}
54 changes: 54 additions & 0 deletions AElf.Kernel.Tests/BlockTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.Threading.Tasks;
using AElf.Kernel.KernelAccount;
using Xunit;
using Xunit.Frameworks.Autofac;

namespace AElf.Kernel.Tests
{
[UseAutofacTestFramework]
public class BlockTest
{
private IBlockManager _blockManager;
private ISmartContractZero _smartContractZero;
private ChainTest _chainTest;


public BlockTest(IBlockManager blockManager, ISmartContractZero smartContractZero, ChainTest chainTest)
{
_blockManager = blockManager;
_smartContractZero = smartContractZero;
_chainTest = chainTest;
}



[Fact]
public void GenesisBlockBuilderTest()
{
var builder = new GenesisBlockBuilder().Build(_smartContractZero.GetType());
var genesisBlock = builder.Block;
var txs = builder.Txs;
Assert.NotNull(genesisBlock);
Assert.Equal(genesisBlock.Header.PreviousHash, Hash.Zero);
Assert.NotNull(txs);
}

[Fact]
public async Task BlockManagerTest()
{
var builder = new GenesisBlockBuilder().Build(_smartContractZero.GetType());
var genesisBlock = builder.Block;

await _blockManager.AddBlockAsync(genesisBlock);
var blockHeader = await _blockManager.GetBlockHeaderAsync(genesisBlock.GetHash());

var block = new Block(genesisBlock.GetHash());

var chain = await _chainTest.CreateChainTest();
await _chainTest.AppendBlockTest(chain, block);
Assert.Equal(blockHeader, genesisBlock.Header);
}


}
}
67 changes: 67 additions & 0 deletions AElf.Kernel.Tests/ChainTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Threading.Tasks;
using AElf.Kernel.KernelAccount;
using Xunit;
using Xunit.Frameworks.Autofac;

namespace AElf.Kernel.Tests
{
[UseAutofacTestFramework]
public class ChainTest
{
private readonly IChainCreationService _chainCreationService;
private readonly ISmartContractZero _smartContractZero;
private readonly IChainManager _chainManager;
private readonly IChainContextService _chainContextService;

public ChainTest(ISmartContractZero smartContractZero, IChainCreationService chainCreationService,
IChainManager chainManager, IChainContextService chainContextService)
{
_smartContractZero = smartContractZero;
_chainCreationService = chainCreationService;
_chainManager = chainManager;
_chainContextService = chainContextService;
}

[Fact]
public async Task<Chain> CreateChainTest()
{
var chainId = Hash.Generate();
var chain = await _chainCreationService.CreateNewChainAsync(chainId, _smartContractZero.GetType());
var adp = new AccountDataProvider
{
Context =
{
Address = new Hash(new byte[] {1, 2, 3}),
ChainId = chainId
}
};
await _smartContractZero.InitializeAsync(adp);
Assert.Equal(chain.CurrentBlockHeight, (ulong)1);
return chain;
}

public async Task ChainStoreTest(Hash chainId)
{
await _chainManager.AddChainAsync(chainId);
Assert.NotNull(_chainManager.GetChainAsync(chainId).Result);
}

public async Task ChainContextTest()
{
var chain = await CreateChainTest();
await _chainManager.AddChainAsync(chain.Id);
chain = await _chainManager.GetChainAsync(chain.Id);
var context = _chainContextService.GetChainContext(chain.Id);
Assert.NotNull(context);
Assert.Equal(context.SmartContractZero, _smartContractZero);
}

public async Task AppendBlockTest(Chain chain, Block block)
{
await _chainManager.AppendBlockToChainAsync(chain, block);
Assert.Equal(chain.CurrentBlockHeight, (ulong)2);
Assert.Equal(chain.CurrentBlockHash, block.GetHash());
}
}
}
46 changes: 21 additions & 25 deletions AElf.Kernel.Tests/TransactionSchedulerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ private IAccount CreateAccount(byte b)
return account.Object;
}

private List<IAccount> CreateAccountList(int accountCount)
private List<Hash> CreateHashList(int accountCount)
{
List<IAccount> accounts = new List<IAccount>();
List<Hash> hashes = new List<Hash>();
for (int j = 0; j < accountCount; j++)
{
accounts.Add(CreateAccount((byte)(j + 'a')));
hashes.Add(CreateHash((byte)(j + 'a')).Object);
}
return accounts;
return hashes;
}


Expand All @@ -64,29 +64,25 @@ private ITransaction CreateTransaction(byte b, Hash from, Hash to)
return transaction.Object;
}

/*

[Fact]
public void SchedulerTest()
{

var worldState = new WorldState();
var smartContractZero = new SmartContractZero();
var accountZero = new AccountZero(smartContractZero);
var accountManager = new AccountManager(worldState);
ISmartContractManager sm = null;
var transactionExecutingManager = new TransactionExecutingManager(worldState, accountZero, accountManager,sm);
ISmartContractService sm = null;
IChainContext context = null;
var transactionExecutingManager = new TransactionExecutingManager(sm);

// simple demo cases


var accounts = CreateAccountList(10);
var accounts = CreateHashList(10);
// one tx
// A
var tx1 = CreateTransaction((byte) 'A', accounts[0], accounts[1]);

var transactions = new List<ITransaction> {tx1};

transactionExecutingManager.Schedule(transactions);
transactionExecutingManager.Schedule(transactions, context);

var plan = transactionExecutingManager.ExecutingPlan;
Assert.Equal(1, plan.Count);
Expand All @@ -98,7 +94,7 @@ public void SchedulerTest()
// A B
var tx2 = CreateTransaction((byte) 'B', accounts[2], accounts[3] );
transactions = new List<ITransaction>{tx1, tx2};
transactionExecutingManager.Schedule(transactions);
transactionExecutingManager.Schedule(transactions, context);
plan = transactionExecutingManager.ExecutingPlan;
Assert.Equal(1, plan.Count);
Assert.Equal(65, plan[0].ElementAt(0).GetHash().GetHashBytes()[0]);
Expand All @@ -111,7 +107,7 @@ public void SchedulerTest()
// A-B
tx2 = CreateTransaction((byte) 'B', accounts[0], accounts[1] );
transactions = new List<ITransaction>{tx1, tx2};
transactionExecutingManager.Schedule(transactions);
transactionExecutingManager.Schedule(transactions, context);
plan = transactionExecutingManager.ExecutingPlan;
Assert.Equal(2, plan.Count);
Assert.Equal(65, plan[0].ElementAt(0).GetHash().GetHashBytes()[0]);
Expand All @@ -127,7 +123,7 @@ public void SchedulerTest()
// A-B C
var tx3 = CreateTransaction((byte) 'C', accounts[2], accounts[3]);
transactions = new List<ITransaction>{tx1, tx2, tx3};
transactionExecutingManager.Schedule(transactions);
transactionExecutingManager.Schedule(transactions, context);
plan = transactionExecutingManager.ExecutingPlan;
Assert.Equal(2, plan.Count);
Assert.Equal(65, plan[0].ElementAt(0).GetHash().GetHashBytes()[0]);
Expand All @@ -139,7 +135,7 @@ public void SchedulerTest()
tx2 = CreateTransaction((byte) 'B', accounts[1], accounts[2]);
tx3 = CreateTransaction((byte) 'C', accounts[2], accounts[3]);
transactions = new List<ITransaction>{tx1, tx2, tx3};
transactionExecutingManager.Schedule(transactions);
transactionExecutingManager.Schedule(transactions, context);
plan = transactionExecutingManager.ExecutingPlan;
Assert.Equal(2, plan.Count);
Assert.Equal(65, plan[0].ElementAt(0).GetHash().GetHashBytes()[0]);
Expand All @@ -153,7 +149,7 @@ public void SchedulerTest()

tx3 = CreateTransaction((byte) 'C', accounts[0], accounts[2]);
transactions = new List<ITransaction>{tx1, tx2, tx3};
transactionExecutingManager.Schedule(transactions);
transactionExecutingManager.Schedule(transactions, context);
plan = transactionExecutingManager.ExecutingPlan;
Assert.Equal(3, plan.Count);
Assert.Equal(65, plan[0].ElementAt(0).GetHash().GetHashBytes()[0]);
Expand All @@ -169,7 +165,7 @@ public void SchedulerTest()
tx3 = CreateTransaction((byte) 'C', accounts[3], accounts[4]);
var tx4 = CreateTransaction((byte) 'D', accounts[5], accounts[6]);
transactions = new List<ITransaction>{tx1, tx2, tx3, tx4};
transactionExecutingManager.Schedule(transactions);
transactionExecutingManager.Schedule(transactions, context);
plan = transactionExecutingManager.ExecutingPlan;
Assert.Equal(2, plan.Count);
Assert.Equal(65, plan[0].ElementAt(0).GetHash().GetHashBytes()[0]);
Expand All @@ -185,7 +181,7 @@ public void SchedulerTest()
tx4 = CreateTransaction((byte) 'D', accounts[4], accounts[5]);

transactions = new List<ITransaction>{tx1, tx2, tx3, tx4};
transactionExecutingManager.Schedule(transactions);
transactionExecutingManager.Schedule(transactions, context);
plan = transactionExecutingManager.ExecutingPlan;
Assert.Equal(2, plan.Count);
Assert.Equal(65, plan[0].ElementAt(0).GetHash().GetHashBytes()[0]);
Expand All @@ -212,7 +208,7 @@ public void SchedulerTest()
tx4 = CreateTransaction((byte) 'D', accounts[3], accounts[0]);

transactions = new List<ITransaction>{tx1, tx2, tx3, tx4};
transactionExecutingManager.Schedule(transactions);
transactionExecutingManager.Schedule(transactions, context);
plan = transactionExecutingManager.ExecutingPlan;
Assert.Equal(2, plan.Count);
Assert.Equal(65, plan[0].ElementAt(0).GetHash().GetHashBytes()[0]);
Expand All @@ -230,7 +226,7 @@ public void SchedulerTest()
tx4 = CreateTransaction((byte) 'D', accounts[3], accounts[0]);

transactions = new List<ITransaction>{tx1, tx2, tx3, tx4};
transactionExecutingManager.Schedule(transactions);
transactionExecutingManager.Schedule(transactions, context);
plan = transactionExecutingManager.ExecutingPlan;
Assert.Equal(3, plan.Count);
Assert.Equal(65, plan[0].ElementAt(0).GetHash().GetHashBytes()[0]);
Expand All @@ -246,7 +242,7 @@ public void SchedulerTest()
tx4 = CreateTransaction((byte) 'D', accounts[0], accounts[1]);

transactions = new List<ITransaction>{tx1, tx2, tx3, tx4};
transactionExecutingManager.Schedule(transactions);
transactionExecutingManager.Schedule(transactions, context);
plan = transactionExecutingManager.ExecutingPlan;
Assert.Equal(4, plan.Count);
Assert.Equal(65, plan[0].ElementAt(0).GetHash().GetHashBytes()[0]);
Expand All @@ -255,7 +251,7 @@ public void SchedulerTest()
Assert.Equal(68, plan[3].ElementAt(0).GetHash().GetHashBytes()[0]);

}
*/


}
}
4 changes: 2 additions & 2 deletions AElf.Kernel/Account.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;

namespace AElf.Kernel
{
Expand Down Expand Up @@ -29,4 +29,4 @@ public Hash GetAddress()
return Address;
}
}
}
}
19 changes: 0 additions & 19 deletions AElf.Kernel/AccountManager.cs

This file was deleted.

2 changes: 1 addition & 1 deletion AElf.Kernel/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void FillTxsMerkleTreeRootInHeader()
/// <returns>The hash.</returns>
public Hash GetHash()
{
return new Hash(this.Header.CalculateHash());
return Header.Hash;
}
}
}
8 changes: 8 additions & 0 deletions AElf.Kernel/BlockHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ public BlockHeader(Hash preBlockHash)


public Hash PreviousHash { get; set; }

public Hash Hash => new Hash(this.CalculateHash());

/// <summary>
/// block index in chain
/// </summary>
public ulong Index { get; set;}




Expand Down
Loading