Skip to content

Commit

Permalink
Merge branch 'development' into EN-4225-termui-new-metrics-rewards
Browse files Browse the repository at this point in the history
# Conflicts:
#	process/block/shardblock.go
  • Loading branch information
miiu96 committed Oct 14, 2019
2 parents 4c1152b + 2339c8b commit ed75446
Show file tree
Hide file tree
Showing 40 changed files with 2,387 additions and 1,067 deletions.
37 changes: 21 additions & 16 deletions cmd/node/factory/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1723,7 +1723,7 @@ func newShardBlockProcessor(
Core: coreServiceContainer,
}
arguments := block.ArgShardProcessor{
ArgBaseProcessor: &argumentsBaseProcessor,
ArgBaseProcessor: argumentsBaseProcessor,
DataPool: data.Datapool,
TxCoordinator: txCoordinator,
TxsPoolsCleaner: txPoolsCleaner,
Expand Down Expand Up @@ -1762,21 +1762,26 @@ func newMetaBlockProcessor(
return nil, err
}

metaProcessor, err := block.NewMetaProcessor(
coreServiceContainer,
state.AccountsAdapter,
data.MetaDatapool,
forkDetector,
shardCoordinator,
nodesCoordinator,
specialAddressHandler,
core.Hasher,
core.Marshalizer,
data.Store,
shardsGenesisBlocks,
requestHandler,
core.Uint64ByteSliceConverter,
)
argumentsBaseProcessor := block.ArgBaseProcessor{
Accounts: state.AccountsAdapter,
ForkDetector: forkDetector,
Hasher: core.Hasher,
Marshalizer: core.Marshalizer,
Store: data.Store,
ShardCoordinator: shardCoordinator,
NodesCoordinator: nodesCoordinator,
SpecialAddressHandler: specialAddressHandler,
Uint64Converter: core.Uint64ByteSliceConverter,
StartHeaders: shardsGenesisBlocks,
RequestHandler: requestHandler,
Core: coreServiceContainer,
}
arguments := block.ArgMetaProcessor{
ArgBaseProcessor: argumentsBaseProcessor,
DataPool: data.MetaDatapool,
}

metaProcessor, err := block.NewMetaProcessor(arguments)
if err != nil {
return nil, errors.New("could not create block processor: " + err.Error())
}
Expand Down
36 changes: 36 additions & 0 deletions core/genesis/genesisBlockCreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"github.com/ElrondNetwork/elrond-go/data"
"github.com/ElrondNetwork/elrond-go/data/block"
"github.com/ElrondNetwork/elrond-go/data/state"
"github.com/ElrondNetwork/elrond-go/data/transaction"
"github.com/ElrondNetwork/elrond-go/process"
"github.com/ElrondNetwork/elrond-go/sharding"
"github.com/ElrondNetwork/elrond-go/vm"
)

var log = logger.DefaultLogger()
Expand Down Expand Up @@ -138,3 +140,37 @@ func setBalanceToTrie(

return account.SetBalanceWithJournal(balance)
}

func initSystemSmartContracts(
accounts state.AccountsAdapter,
adrConv state.AddressConverter,
processor process.SmartContractProcessor,
smartContracts vm.SystemSCContainer,
) ([]byte, error) {
scKeys := smartContracts.Keys()

tx := &transaction.Transaction{
Value: big.NewInt(0),
RcvAddr: make([]byte, adrConv.AddressLen()),
}
for _, scKey := range scKeys {
tx.SndAddr = scKey

adrSrc, err := adrConv.CreateAddressFromPublicKeyBytes(tx.SndAddr)
if err != nil {
return nil, err
}

acntSrc, err := accounts.GetAccountWithJournal(adrSrc)
if err != nil {
return nil, err
}

err = processor.DeploySmartContract(tx, acntSrc, 0)
if err != nil {
return nil, err
}
}

return accounts.Commit()
}
14 changes: 7 additions & 7 deletions integrationTests/mock/intermediateTransactionHandlerMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ type IntermediateTransactionHandlerMock struct {
GetAllCurrentFinishedTxsCalled func() map[string]data.TransactionHandler
}

func (ith *IntermediateTransactionHandlerMock) GetAllCurrentFinishedTxs() map[string]data.TransactionHandler {
if ith.GetAllCurrentFinishedTxsCalled != nil {
return ith.GetAllCurrentFinishedTxsCalled()
}
return nil
}

func (ith *IntermediateTransactionHandlerMock) CreateMarshalizedData(txHashes [][]byte) ([][]byte, error) {
if ith.CreateMarshalizedDataCalled == nil {
return nil, nil
Expand Down Expand Up @@ -55,13 +62,6 @@ func (ith *IntermediateTransactionHandlerMock) CreateBlockStarted() {
}
}

func (ith *IntermediateTransactionHandlerMock) GetAllCurrentFinishedTxs() map[string]data.TransactionHandler {
if ith.GetAllCurrentFinishedTxsCalled != nil {
return ith.GetAllCurrentFinishedTxsCalled()
}
return nil
}

// IsInterfaceNil returns true if there is no value under the interface
func (ith *IntermediateTransactionHandlerMock) IsInterfaceNil() bool {
if ith == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func TestProcessSCCallsInMultiShardArchitecture_FirstShard(t *testing.T) {
generalRoundNumber++

// setting the sc deployment address (printed by the transaction processor)
scDeploymentAdddress, _ := hex.DecodeString("00000000000000000000cca1490e8cd87c767da41cdab632a7a206c5703c3132")
scDeploymentAdddress, _ := hex.DecodeString("0000000000000000ffffcca1490e8cd87c767da41cdab632a7a206c5703c3132")

// Now that the SC is deployed, we test a call from an account located in the first shard
addValue := uint64(100)
Expand Down Expand Up @@ -220,7 +220,7 @@ func TestProcessSCCallsInMultiShardArchitecture_FirstShardReceivesCallFromSecond
generalRoundNumber++

// setting the sc deployment address (printed by the transaction processor)
scDeploymentAdddress, _ := hex.DecodeString("00000000000000000000cca1490e8cd87c767da41cdab632a7a206c5703c3132")
scDeploymentAdddress, _ := hex.DecodeString("0000000000000000ffffcca1490e8cd87c767da41cdab632a7a206c5703c3132")

// Now that the SC is deployed, we test a call from an account located in the second shard
addValue := uint64(100)
Expand Down Expand Up @@ -316,7 +316,7 @@ func TestProcessSCCallsInMultiShardArchitecture_FirstShardReceivesCallFromSecond
generalRoundNumber++

// setting the sc deployment address (printed by the transaction processor)
scDeploymentAdddress, _ := hex.DecodeString("00000000000000000000cca1490e8cd87c767da41cdab632a7a206c5703c3132")
scDeploymentAdddress, _ := hex.DecodeString("0000000000000000ffffcca1490e8cd87c767da41cdab632a7a206c5703c3132")

// Update the SC account balance so we can call withdraw function
createMintingForSenders(nodes[0], scShard, [][]byte{scDeploymentAdddress}, mintingValue)
Expand Down
60 changes: 32 additions & 28 deletions integrationTests/multiShard/smartContract/testInitializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ func createNetNode(
genesisBlocks := createGenesisBlocks(shardCoordinator)

arguments := block.ArgShardProcessor{
ArgBaseProcessor: &block.ArgBaseProcessor{
ArgBaseProcessor: block.ArgBaseProcessor{
Accounts: accntAdapter,
ForkDetector: &mock.ForkDetectorMock{
AddHeaderCalled: func(header data.HeaderHandler, hash []byte, state process.BlockHeaderState, finalHeaders []data.HeaderHandler, finalHeadersHashes [][]byte) error {
Expand Down Expand Up @@ -800,35 +800,39 @@ func createMetaNetNode(
requestHandler, _ := requestHandlers.NewMetaResolverRequestHandler(resolvers, factory.ShardHeadersForMetachainTopic, factory.MetachainBlocksTopic)

genesisBlocks := createGenesisBlocks(shardCoordinator)
blkProc, _ := block.NewMetaProcessor(
&mock.ServiceContainerMock{},
accntAdapter,
dPool,
&mock.ForkDetectorMock{
AddHeaderCalled: func(header data.HeaderHandler, hash []byte, state process.BlockHeaderState, finalHeaders []data.HeaderHandler, finalHeadersHashes [][]byte) error {
return nil
},
GetHighestFinalBlockNonceCalled: func() uint64 {
return 0
},
ProbableHighestNonceCalled: func() uint64 {
return 0

arguments := block.ArgMetaProcessor{
ArgBaseProcessor: block.ArgBaseProcessor{
Accounts: accntAdapter,
ForkDetector: &mock.ForkDetectorMock{
AddHeaderCalled: func(header data.HeaderHandler, hash []byte, state process.BlockHeaderState, finalHeaders []data.HeaderHandler, finalHeadersHashes [][]byte) error {
return nil
},
GetHighestFinalBlockNonceCalled: func() uint64 {
return 0
},
ProbableHighestNonceCalled: func() uint64 {
return 0
},
},
Hasher: testHasher,
Marshalizer: testMarshalizer,
Store: store,
ShardCoordinator: shardCoordinator,
NodesCoordinator: nodesCoordinator,
SpecialAddressHandler: mock.NewSpecialAddressHandlerMock(
testAddressConverter,
shardCoordinator,
nodesCoordinator,
),
Uint64Converter: uint64Converter,
StartHeaders: genesisBlocks,
RequestHandler: requestHandler,
Core: &mock.ServiceContainerMock{},
},
shardCoordinator,
nodesCoordinator,
mock.NewSpecialAddressHandlerMock(
testAddressConverter,
shardCoordinator,
nodesCoordinator,
),
testHasher,
testMarshalizer,
store,
genesisBlocks,
requestHandler,
uint64Converter,
)
DataPool: dPool,
}
blkProc, _ := block.NewMetaProcessor(arguments)

_ = tn.blkc.SetGenesisHeader(genesisBlocks[sharding.MetachainShardId])

Expand Down
58 changes: 26 additions & 32 deletions integrationTests/testProcessorNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,41 +497,35 @@ func (tpn *TestProcessorNode) initBlockProcessor() {
},
}

argumentsBase := block.ArgBaseProcessor{
Accounts: tpn.AccntState,
ForkDetector: tpn.ForkDetector,
Hasher: TestHasher,
Marshalizer: TestMarshalizer,
Store: tpn.Storage,
ShardCoordinator: tpn.ShardCoordinator,
NodesCoordinator: tpn.NodesCoordinator,
SpecialAddressHandler: tpn.SpecialAddressHandler,
Uint64Converter: TestUint64Converter,
StartHeaders: tpn.GenesisBlocks,
RequestHandler: tpn.RequestHandler,
Core: nil,
}

if tpn.ShardCoordinator.SelfId() == sharding.MetachainShardId {
tpn.BlockProcessor, err = block.NewMetaProcessor(
&mock.ServiceContainerMock{},
tpn.AccntState,
tpn.MetaDataPool,
tpn.ForkDetector,
tpn.ShardCoordinator,
tpn.NodesCoordinator,
tpn.SpecialAddressHandler,
TestHasher,
TestMarshalizer,
tpn.Storage,
tpn.GenesisBlocks,
tpn.RequestHandler,
TestUint64Converter,
)
argumentsBase.Core = &mock.ServiceContainerMock{}
arguments := block.ArgMetaProcessor{
ArgBaseProcessor: argumentsBase,
DataPool: tpn.MetaDataPool,
}

tpn.BlockProcessor, err = block.NewMetaProcessor(arguments)
} else {
arguments := block.ArgShardProcessor{
ArgBaseProcessor: &block.ArgBaseProcessor{
Accounts: tpn.AccntState,
ForkDetector: tpn.ForkDetector,
Hasher: TestHasher,
Marshalizer: TestMarshalizer,
Store: tpn.Storage,
ShardCoordinator: tpn.ShardCoordinator,
NodesCoordinator: tpn.NodesCoordinator,
SpecialAddressHandler: tpn.SpecialAddressHandler,
Uint64Converter: TestUint64Converter,
StartHeaders: tpn.GenesisBlocks,
RequestHandler: tpn.RequestHandler,
Core: nil,
},
DataPool: tpn.ShardDataPool,
TxCoordinator: tpn.TxCoordinator,
TxsPoolsCleaner: &mock.TxPoolsCleanerMock{},
ArgBaseProcessor: argumentsBase,
DataPool: tpn.ShardDataPool,
TxCoordinator: tpn.TxCoordinator,
TxsPoolsCleaner: &mock.TxPoolsCleanerMock{},
}

tpn.BlockProcessor, err = block.NewShardProcessor(arguments)
Expand Down
60 changes: 28 additions & 32 deletions integrationTests/testSyncNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,44 +79,40 @@ func (tpn *TestProcessorNode) initTestNodeWithSync() {
func (tpn *TestProcessorNode) initBlockProcessorWithSync() {
var err error

argumentsBase := block.ArgBaseProcessor{
Accounts: tpn.AccntState,
ForkDetector: nil,
Hasher: TestHasher,
Marshalizer: TestMarshalizer,
Store: tpn.Storage,
ShardCoordinator: tpn.ShardCoordinator,
NodesCoordinator: tpn.NodesCoordinator,
SpecialAddressHandler: tpn.SpecialAddressHandler,
Uint64Converter: TestUint64Converter,
StartHeaders: tpn.GenesisBlocks,
RequestHandler: tpn.RequestHandler,
Core: nil,
}

if tpn.ShardCoordinator.SelfId() == sharding.MetachainShardId {
tpn.ForkDetector, _ = sync.NewMetaForkDetector(tpn.Rounder)
tpn.BlockProcessor, err = block.NewMetaProcessor(
&mock.ServiceContainerMock{},
tpn.AccntState,
tpn.MetaDataPool,
tpn.ForkDetector,
tpn.ShardCoordinator,
tpn.NodesCoordinator,
tpn.SpecialAddressHandler,
TestHasher,
TestMarshalizer,
tpn.Storage,
tpn.GenesisBlocks,
tpn.RequestHandler,
TestUint64Converter,
)
argumentsBase.Core = &mock.ServiceContainerMock{}
argumentsBase.ForkDetector = tpn.ForkDetector
arguments := block.ArgMetaProcessor{
ArgBaseProcessor: argumentsBase,
DataPool: tpn.MetaDataPool,
}

tpn.BlockProcessor, err = block.NewMetaProcessor(arguments)

} else {
tpn.ForkDetector, _ = sync.NewShardForkDetector(tpn.Rounder)
argumentsBase.ForkDetector = tpn.ForkDetector
arguments := block.ArgShardProcessor{
ArgBaseProcessor: &block.ArgBaseProcessor{
Accounts: tpn.AccntState,
ForkDetector: tpn.ForkDetector,
Hasher: TestHasher,
Marshalizer: TestMarshalizer,
Store: tpn.Storage,
ShardCoordinator: tpn.ShardCoordinator,
NodesCoordinator: tpn.NodesCoordinator,
SpecialAddressHandler: tpn.SpecialAddressHandler,
Uint64Converter: TestUint64Converter,
StartHeaders: tpn.GenesisBlocks,
RequestHandler: tpn.RequestHandler,
Core: nil,
},
DataPool: tpn.ShardDataPool,
TxCoordinator: tpn.TxCoordinator,
TxsPoolsCleaner: &mock.TxPoolsCleanerMock{},
ArgBaseProcessor: argumentsBase,
DataPool: tpn.ShardDataPool,
TxCoordinator: tpn.TxCoordinator,
TxsPoolsCleaner: &mock.TxPoolsCleanerMock{},
}

tpn.BlockProcessor, err = block.NewShardProcessor(arguments)
Expand Down
Loading

0 comments on commit ed75446

Please sign in to comment.