This commit is contained in:
peterpy8 2018-06-25 05:59:06 +00:00 committed by GitHub
commit e9730f7d61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 267 additions and 1 deletions

26
2nodetest.sh Executable file
View file

@ -0,0 +1,26 @@
#!/bin/sh
Datadir0="~/.mainnode"
Datadir1="~/.peernode"
#build/bin/geth --datadir $Datadir0 removedb
#build/bin/geth --datadir $Datadir1 removedb
rm -rf ~/.ethash
rm -rf $Datadir0
rm -rf $Datadir1
echo "node datadir cleared"
echo "main node init"
build/bin/geth --datadir $Datadir0 init genesis.json
build/bin/geth --datadir $Datadir0 --port 30303 --networkid 9876 --exec 'loadScript("yapen/mainnode.js")' console &
sleep 4s
echo "peer node init"
build/bin/geth --datadir $Datadir1 init genesis.json
build/bin/geth --datadir $Datadir1 --port 30304 --networkid 9876 --exec 'loadScript("yapen/peernode.js")' console
echo "all command executed"

View file

@ -287,8 +287,10 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent *
// CalcDifficulty is the difficulty adjustment algorithm. It returns // CalcDifficulty is the difficulty adjustment algorithm. It returns
// the difficulty that a new block should have when created at time // the difficulty that a new block should have when created at time
// given the parent block's time and difficulty. // given the parent block's time and difficulty.
// TODO Wei: update the difficulty calculation function to reduce the rate of blck difficulty increment
func (ethash *Ethash) CalcDifficulty(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int { func (ethash *Ethash) CalcDifficulty(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int {
return CalcDifficulty(chain.Config(), time, parent) //return CalcDifficulty(chain.Config(), time, parent)
return big.NewInt(0x200)
} }
// CalcDifficulty is the difficulty adjustment algorithm. It returns // CalcDifficulty is the difficulty adjustment algorithm. It returns

10
count_eth.sh Normal file
View file

@ -0,0 +1,10 @@
#!/bin/sh
dirlist=$(find -mindepth 1 -maxdepth 1 -type d)
for dir in $dirlist
do
cd $dir
echo $dir
grep -i eth -r | wc -l
cd ..
done

74
current_count.tsv Normal file
View file

@ -0,0 +1,74 @@
./.git
13
./.github
6
./accounts
865
./bmt
20
./build
136
./cmd
1599
./common
194
./consensus
368
./console
100
./containers
20
./contracts
312
./core
1290
./crypto
158
./dashboard
275
./eth
1194
./ethclient
88
./ethdb
36
./ethstats
55
./event
73
./internal
919
./les
560
./light
246
./log
45
./metrics
31
./miner
109
./mobile
329
./node
163
./p2p
657
./params
85
./rlp
66
./rpc
337
./signer
235
./swarm
616
./tests
154
./trie
206
./vendor
5513
./whisper
300
1 ./.git
2 13
3 ./.github
4 6
5 ./accounts
6 865
7 ./bmt
8 20
9 ./build
10 136
11 ./cmd
12 1599
13 ./common
14 194
15 ./consensus
16 368
17 ./console
18 100
19 ./containers
20 20
21 ./contracts
22 312
23 ./core
24 1290
25 ./crypto
26 158
27 ./dashboard
28 275
29 ./eth
30 1194
31 ./ethclient
32 88
33 ./ethdb
34 36
35 ./ethstats
36 55
37 ./event
38 73
39 ./internal
40 919
41 ./les
42 560
43 ./light
44 246
45 ./log
46 45
47 ./metrics
48 31
49 ./miner
50 109
51 ./mobile
52 329
53 ./node
54 163
55 ./p2p
56 657
57 ./params
58 85
59 ./rlp
60 66
61 ./rpc
62 337
63 ./signer
64 235
65 ./swarm
66 616
67 ./tests
68 154
69 ./trie
70 206
71 ./vendor
72 5513
73 ./whisper
74 300

11
genesis.json Normal file
View file

@ -0,0 +1,11 @@
{
"config": {
"chainId": 987,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"difficulty": "0x200",
"gasLimit": "0x8000000",
"alloc": {}
}

47
node0.js Normal file
View file

@ -0,0 +1,47 @@
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
function interaction() {
personal.newAccount("123456")
personal.newAccount("123456")
acc0 = web3.eth.accounts[0]
acc1 = web3.eth.accounts[1]
console.log("account list: " + eth.accounts)
console.log("acc0 balance: " + web3.fromWei(web3.eth.getBalance(acc0)))
console.log("acc1 balance: " + web3.fromWei(web3.eth.getBalance(acc1)))
miner.setEtherbase(eth.accounts[0])
miner.start()
while (1) {
balance = web3.fromWei(web3.eth.getBalance(acc0))
if (balance > 0) {
miner.stop()
personal.unlockAccount(acc0, "123456")
eth.sendTransaction({from:acc0,to:acc1,value:web3.toWei(1,"ether")})
miner.start()
// sleep(10000)
// if (balance1 = balance - 1) {
while (1) {
balance1 = web3.fromWei(web3.eth.getBalance(acc1))
if (balance1 > 0) {
miner.stop()
break
}
}
console.log("acc0 balance: " + web3.fromWei(web3.eth.getBalance(acc0)))
console.log("acc1 balance: " + web3.fromWei(web3.eth.getBalance(acc1)))
// }
break
}
}
console.log(admin.nodeInfo.id)
}
interaction()

7
node0.sh Normal file
View file

@ -0,0 +1,7 @@
rm -rf /home/vivid/.ethereum/*
echo "main node datadir cleared"
./geth --datadir /home/vivid/.ethereum init genesis.json
sleep 1s
./geth --datadir /home/vivid/.ethereum --port 30303 --networkid 9876 console

19
node1.js Normal file
View file

@ -0,0 +1,19 @@
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
function interaction() {
console.log("peer count: " + net.peerCount)
admin.addPeer("enode://a321db2296eb0078fab331d27460456f9c66c478049ee34441595d9c4fc4391af31f24b81fcdf21f28a7e391d07ab4fc550b6e235021abad310992f32d2fc876@127.0.0.1:30303")
sleep(5000)
console.log("peer count: " + net.peerCount)
}
interaction()

7
node1.sh Normal file
View file

@ -0,0 +1,7 @@
rm -rf /home/vivid/peernode/*
echo "peer node datadir cleared"
./geth --datadir /home/vivid/peernode init genesis.json
sleep 1s
./geth --datadir /home/vivid/peernode --port 30304 --networkid 9876 console

40
yapen/mainnode.js Normal file
View file

@ -0,0 +1,40 @@
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
function interaction() {
personal.newAccount("123456")
acc0 = web3.eth.accounts[0]
acc1 = web3.eth.accounts[1]
console.log("[mainnode]: account list: " + eth.accounts)
console.log("[mainnode]: acc0 balance: " + web3.fromWei(web3.eth.getBalance(acc0)))
console.log("[mainnode]: acc1 balance: " + web3.fromWei(web3.eth.getBalance(acc1)))
miner.setEtherbase(eth.accounts[0])
miner.start()
personal.unlockAccount(acc0, "123456")
eth.sendTransaction({from:acc0,to:acc1,value:web3.toWei(1,"ether")})
while (1) {
balance0 = web3.fromWei(web3.eth.getBalance(acc0))
balance1 = web3.fromWei(web3.eth.getBalance(acc1))
if (balance0 >0 && balance1 > 0) {
miner.stop()
break
}
sleep(1000)
}
console.log("[mainnode]: acc0 balance: " + web3.fromWei(web3.eth.getBalance(acc0)))
console.log("[mainnode]: acc1 balance: " + web3.fromWei(web3.eth.getBalance(acc1)))
console.log("[mainnode]: admin.nodeInfo: " + admin.nodeInfo.id)
sleep(5000)
}
interaction()

23
yapen/peernode.js Normal file
View file

@ -0,0 +1,23 @@
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
function interaction() {
console.log("[peermode]: peer count: " + net.peerCount)
//admin.addPeer("enode://a321db2296eb0078fab331d27460456f9c66c478049ee34441595d9c4fc4391af31f24b81fcdf21f28a7e391d07ab4fc550b6e235021abad310992f32d2fc876@127.0.0.1:30303")
console.log("[peermode]: connect to [::]:30303")
admin.addPeer("enode://07a0106f92170dd3fc3ffa201c5b0708c8b3b92f73ad58b6f21a43338eea924b53e0a1d942c70f582127f10fb86b569c10dabcc97fa308a90f23aa6003c5b76c@[::]:30303")
while (net.peerCount == 0)
{
sleep(1000)
console.log("[peermode]: peer count: " + net.peerCount)
}
}
interaction()