Skip to content

Commit

Permalink
README fixed, add missing configs to test nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
graninas committed Dec 4, 2018
1 parent 862f74f commit 5a1df73
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 32 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,39 +102,39 @@ Run slow and unreliable tests:
- Answers for balance requests.
- Has a wide API, can answer to many different requests.

`stack exec enq-test-node-haskell singlenode ./configs/GraphNodeTransmitter.json`
`stack exec enq-test-node-haskell singlenode ./configs/tst_graph_node_transmitter.json`

* GraphNode Receiver
- Works with blockchain graph and ledger.
- Polls the Transmitter node to synchronize with it. Implements a basic synchronisation scenario.

`stack exec enq-test-node-haskell singlenode ./configs/GraphNodeReceiver.json`
`stack exec enq-test-node-haskell singlenode ./configs/tst_graph_node_receiver.json`

* Gen PoW
- Controllable from the Client node.
- By the command from Client, generates KBlocks organized in a chain, but without hash complexity (does not do any mining).
- Sends KBlocks to GraphNode Transmitter.

`stack exec enq-test-node-haskell singlenode ./configs/pow.json`
`stack exec enq-test-node-haskell singlenode ./configs/tst_gen_pow.json`

* Gen PoA
- Polls the Transmitter and generates a microblock for an empty KBlock found.
- Fills the microblock by random transactions for random wallets (5 wallets are hardcoded).

`stack exec enq-test-node-haskell singlenode ./configs/poa.json`
`stack exec enq-test-node-haskell singlenode ./configs/tst_gen_poa.json`

* Console client
- Has console API.
- Allows to create wallets, send transactions, ask balance.
- Sends commands to nodes.

`stack exec enq-test-node-haskell singlenode ./configs/Client.json`
`stack exec enq-test-node-haskell singlenode ./configs/tst_client.json`

# Node code sample

- Server logic: [Enecuum.Assets.Nodes.TstNodes.PingPong.PingServer](./src/Enecuum/Assets/Nodes/TstNodes/PingPong/PingServer.hs)
- Client logic: [Enecuum.Assets.Nodes.TstNodes.PingPong.PongClient](./src/Enecuum/Assets/Nodes/TstNodes/PingPong/PongClient.hs)
- Configs:
* Server logic: [Enecuum.Assets.Nodes.TstNodes.PingPong.PingServer](./src/Enecuum/Assets/Nodes/TstNodes/PingPong/PingServer.hs)
* Client logic: [Enecuum.Assets.Nodes.TstNodes.PingPong.PongClient](./src/Enecuum/Assets/Nodes/TstNodes/PingPong/PongClient.hs)
* Configs:
- [./configs/tst_ping_server.json](./configs/tst_ping_server.json)
- [./configs/tst_pong_client1.json](./configs/tst_pong_client1.json)
- [./configs/tst_pong_client2.json](./configs/tst_pong_client2.json)
Expand Down
4 changes: 3 additions & 1 deletion configs/tst_gen_poa.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
{
"tag": "TstGenPoANodeConfig",
"controlRpcPort": 6200,
"genPoaGraphNodeUDPAddress": {"host":"127.0.0.1","port":4050},
"genPoaGraphNodeRPCAddress": {"host":"127.0.0.1","port":6050}
},
"loggerConfig":
{
"logFilePath": "/tmp/log/tst_poa.log",
"logFilePath": "/tmp/log/tst_gen_poa.log",
"format":"$prio $loggername: $msg",
"logToConsole":true,
"logToFile": true,
Expand Down
6 changes: 3 additions & 3 deletions configs/tst_gen_pow.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"defaultBlocksDelay":1000000,
"tag": "TstGenPoWNodeConfig",
"kblocksOrder": "InOrder",
"graphNodeUDPAddress": {"host":"127.0.0.1","port":4050},
"controlRpcPort": 6201
"genPowGraphNodeUDPAddress": {"host":"127.0.0.1","port":4050},
"controlRpcPort": 6300
},
"loggerConfig":
{
"logFilePath": "/tmp/log/tst_pow.log",
"logFilePath": "/tmp/log/tst_gen_pow.log",
"format":"$prio $loggername: $msg",
"logToConsole":true,
"logToFile": true,
Expand Down
4 changes: 2 additions & 2 deletions configs/tst_graph_node_receiver.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"graphWindowConfig": {
"tag": "GraphWindowConfig",
"shrinkingEnabled": true,
"shrinkingEnabled": false,
"windowSize": 100,
"shrinkingDelay": 1000000
},
Expand All @@ -34,7 +34,7 @@
},
"node": "TstGraphNode",
"loggerConfig": {
"logFilePath": "/tmp/log/GraphNodeReceiver.log",
"logFilePath": "/tmp/log/tst_graph_node_receiver.log",
"format": "$prio $loggername: $msg",
"logToFile": true,
"logToConsole": true,
Expand Down
4 changes: 2 additions & 2 deletions configs/tst_graph_node_transmitter.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"graphWindowConfig": {
"tag": "GraphWindowConfig",
"shrinkingEnabled": true,
"shrinkingEnabled": false,
"windowSize": 100,
"shrinkingDelay": 1000000
},
Expand All @@ -31,7 +31,7 @@
},
"node": "TstGraphNode",
"loggerConfig": {
"logFilePath": "/tmp/log/GraphNodeTransmitter.log",
"logFilePath": "/tmp/log/tst_graph_node_transmitter.log",
"format": "$prio $loggername: $msg",
"logToFile": true,
"logToConsole": true,
Expand Down
7 changes: 6 additions & 1 deletion src/Enecuum/Assets/Nodes/TstNodes/GenPoA/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ data TstGenPoANode = TstGenPoANode

data instance NodeConfig TstGenPoANode = TstGenPoANodeConfig
{ _controlRpcPort :: D.PortNumber
, _genPoaGraphNodeUDPAddress :: D.Address
, _genPoaGraphNodeRPCAddress :: D.Address
}
deriving (Show, Generic)

Expand All @@ -24,4 +26,7 @@ instance ToJSON (NodeConfig TstGenPoANode) where toJSON = A.genericToJSON
instance FromJSON (NodeConfig TstGenPoANode) where parseJSON = A.genericParseJSON nodeConfigJsonOptions

tstGenPoANodeConfig :: NodeConfig TstGenPoANode
tstGenPoANodeConfig = TstGenPoANodeConfig (tstGenPoANodePorts ^. Lens.nodeRpcPort)
tstGenPoANodeConfig = TstGenPoANodeConfig
(tstGenPoANodePorts ^. Lens.nodeRpcPort)
(getUdpAddress tstGraphNodeTransmitterAddress)
(getRpcAddress tstGraphNodeTransmitterAddress)
10 changes: 5 additions & 5 deletions src/Enecuum/Assets/Nodes/TstNodes/GenPoA/Node.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ instance FromJSON (NodeScenario TstGenPoANode) where parseJSON = A.genericParseJ
showTransactions :: D.Microblock -> Text
showTransactions mBlock = foldr D.showTransaction "" $ mBlock ^. Lens.transactions

sendMicroblock :: TstGenPoANodeData -> D.KBlock -> NodeScenario TstGenPoANode -> L.NodeL ()
sendMicroblock poaData block role = do
sendMicroblock :: D.Address -> TstGenPoANodeData -> D.KBlock -> NodeScenario TstGenPoANode -> L.NodeL ()
sendMicroblock gnUdpAddress poaData block role = do
currentBlock <- L.readVarIO (poaData ^. currentLastKeyBlock)
when (block /= currentBlock) $ do
L.logInfo $ "Empty KBlock found (" +|| toHash block ||+ ")."
Expand All @@ -71,7 +71,6 @@ sendMicroblock poaData block role = do
Bad -> A.generateBogusSignedMicroblock block tx
L.logInfo
$ "MBlock generated (" +|| toHash mBlock ||+ ". Transactions:" +| showTransactions mBlock |+ ""
let gnUdpAddress = A.getUdpAddress A.tstGraphNodeTransmitterAddress
void $ L.withConnection D.Udp gnUdpAddress $
\conn -> L.send conn mBlock

Expand All @@ -91,12 +90,13 @@ poaNode role cfg = do
L.method rpcPingPong
L.method $ handleStopNode poaData

let gnRpcAddress = A.getRpcAddress A.tstGraphNodeTransmitterAddress
let gnRpcAddress = _genPoaGraphNodeRPCAddress cfg
let gnUdpAddress = _genPoaGraphNodeUDPAddress cfg
L.process $ forever $ do
L.delay $ 100 * 1000
whenRightM (L.makeRpcRequest gnRpcAddress GetTransactionPending) $ \tx -> do
forM_ tx (\t -> L.logInfo $ "\nAdd transaction to pending " +| D.showTransaction t "" |+ "")
L.atomically $ L.modifyVar (poaData ^. transactionPending) ( ++ tx )
whenRightM (L.makeRpcRequest gnRpcAddress GetLastKBlock) $ \block -> sendMicroblock poaData block role
whenRightM (L.makeRpcRequest gnRpcAddress GetLastKBlock) $ \block -> sendMicroblock gnUdpAddress poaData block role

L.awaitNodeFinished poaData
16 changes: 8 additions & 8 deletions src/Enecuum/Assets/Nodes/TstNodes/GenPoW/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ data TstGenPoWNode = TstGenPoWNode
deriving (Show, Generic)

data instance NodeConfig TstGenPoWNode = TstGenPoWNodeConfig
{ _defaultBlocksDelay :: BlocksDelay
, _kblocksOrder :: A.Ordering
, _graphNodeUDPAddress :: D.Address
, _controlRpcPort :: D.PortNumber
{ _defaultBlocksDelay :: BlocksDelay
, _kblocksOrder :: A.Ordering
, _genPowGraphNodeUDPAddress :: D.Address
, _controlRpcPort :: D.PortNumber
}
deriving (Show, Generic)

Expand All @@ -30,8 +30,8 @@ instance FromJSON TstGenPoWNode where parseJSON = J.genericParseJSO

tstGenPoWNodeConfig :: NodeConfig TstGenPoWNode
tstGenPoWNodeConfig = TstGenPoWNodeConfig
{ _defaultBlocksDelay = 1000 * 1000
, _kblocksOrder = A.InOrder
, _graphNodeUDPAddress = getUdpAddress tstGraphNodeTransmitterAddress
, _controlRpcPort = tstGenPoWNodePorts ^. Lens.nodeRpcPort
{ _defaultBlocksDelay = 1000 * 1000
, _kblocksOrder = A.InOrder
, _genPowGraphNodeUDPAddress = getUdpAddress tstGraphNodeTransmitterAddress
, _controlRpcPort = tstGenPoWNodePorts ^. Lens.nodeRpcPort
}
2 changes: 1 addition & 1 deletion src/Enecuum/Assets/Nodes/TstNodes/GenPoW/Node.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ powNode' cfg = do
i <- L.readVar $ nodeData ^. requiredBlockNumber
when (i == 0) L.retry
L.writeVar (nodeData ^. requiredBlockNumber) (i - 1)
kBlockProcess (_graphNodeUDPAddress cfg) nodeData
kBlockProcess (_genPowGraphNodeUDPAddress cfg) nodeData

L.awaitNodeFinished nodeData

Expand Down
5 changes: 4 additions & 1 deletion test/Enecuum/Tests/Scenarios/GraphNodeDBSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ dumpAndRestoreGraphTest = do
let powRpcAddress = A.getRpcAddress A.tstGenPoWNodeAddress
let poaRpcAddress = A.getRpcAddress A.tstGenPoANodeAddress

let poaConfig = Tst.TstGenPoANodeConfig (D._port poaRpcAddress)
let poaConfig = Tst.TstGenPoANodeConfig
(D._port poaRpcAddress)
(A.getUdpAddress A.tstGraphNodeTransmitterAddress)
(A.getRpcAddress A.tstGraphNodeTransmitterAddress)

let blocksCount = 3
let blocksDelay = 1000 * 1000
Expand Down

0 comments on commit 5a1df73

Please sign in to comment.