Skip to content

Commit 1033500

Browse files
authored
Merge pull request #1 from microstack-tech/laxhash
XHash implementaiton for Parallax
2 parents c5a4054 + 8c18b93 commit 1033500

File tree

125 files changed

+1828
-1750
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+1828
-1750
lines changed

accounts/abi/bind/backends/simulated.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"github.com/microstack-tech/parallax/common"
3131
"github.com/microstack-tech/parallax/common/hexutil"
3232
"github.com/microstack-tech/parallax/common/math"
33-
"github.com/microstack-tech/parallax/consensus/ethash"
33+
"github.com/microstack-tech/parallax/consensus/xhash"
3434
"github.com/microstack-tech/parallax/core"
3535
"github.com/microstack-tech/parallax/core/bloombits"
3636
"github.com/microstack-tech/parallax/core/rawdb"
@@ -76,9 +76,9 @@ type SimulatedBackend struct {
7676
// and uses a simulated blockchain for testing purposes.
7777
// A simulated backend always uses chainID 1337.
7878
func NewSimulatedBackendWithDatabase(database prldb.Database, alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBackend {
79-
genesis := core.Genesis{Config: params.AllEthashProtocolChanges, GasLimit: gasLimit, Alloc: alloc}
79+
genesis := core.Genesis{Config: params.AllXHashProtocolChanges, GasLimit: gasLimit, Alloc: alloc}
8080
genesis.MustCommit(database)
81-
blockchain, _ := core.NewBlockChain(database, nil, genesis.Config, ethash.NewFaker(), vm.Config{}, nil, nil)
81+
blockchain, _ := core.NewBlockChain(database, nil, genesis.Config, xhash.NewFaker(), vm.Config{}, nil, nil)
8282

8383
backend := &SimulatedBackend{
8484
database: database,
@@ -126,7 +126,7 @@ func (b *SimulatedBackend) Rollback() {
126126
}
127127

128128
func (b *SimulatedBackend) rollback(parent *types.Block) {
129-
blocks, _ := core.GenerateChain(b.config, parent, ethash.NewFaker(), b.database, 1, func(int, *core.BlockGen) {})
129+
blocks, _ := core.GenerateChain(b.config, parent, xhash.NewFaker(), b.database, 1, func(int, *core.BlockGen) {})
130130

131131
b.pendingBlock = blocks[0]
132132
b.pendingState, _ = state.New(b.pendingBlock.Root(), b.blockchain.StateCache(), nil)
@@ -661,7 +661,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
661661
return fmt.Errorf("invalid transaction nonce: got %d, want %d", tx.Nonce(), nonce)
662662
}
663663
// Include tx in chain
664-
blocks, _ := core.GenerateChain(b.config, block, ethash.NewFaker(), b.database, 1, func(number int, block *core.BlockGen) {
664+
blocks, _ := core.GenerateChain(b.config, block, xhash.NewFaker(), b.database, 1, func(number int, block *core.BlockGen) {
665665
for _, tx := range b.pendingBlock.Transactions() {
666666
block.AddTxWithChain(b.blockchain, tx)
667667
}
@@ -775,7 +775,7 @@ func (b *SimulatedBackend) AdjustTime(adjustment time.Duration) error {
775775
b.mu.Lock()
776776
defer b.mu.Unlock()
777777

778-
blocks, _ := core.GenerateChain(b.config, b.blockchain.CurrentBlock(), ethash.NewFaker(), b.database, 1, func(number int, block *core.BlockGen) {
778+
blocks, _ := core.GenerateChain(b.config, b.blockchain.CurrentBlock(), xhash.NewFaker(), b.database, 1, func(number int, block *core.BlockGen) {
779779
block.OffsetTime(int64(adjustment.Seconds()))
780780
})
781781
stateDB, _ := b.blockchain.State()

accounts/abi/bind/backends/simulated_test.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,11 @@ var testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d
104104
// return "hello world";
105105
// }
106106
// }
107-
const abiJSON = `[ { "constant": false, "inputs": [ { "name": "memo", "type": "bytes" } ], "name": "receive", "outputs": [ { "name": "res", "type": "string" } ], "payable": true, "stateMutability": "payable", "type": "function" }, { "anonymous": false, "inputs": [ { "indexed": false, "name": "sender", "type": "address" }, { "indexed": false, "name": "amount", "type": "uint256" }, { "indexed": false, "name": "memo", "type": "bytes" } ], "name": "received", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": false, "name": "sender", "type": "address" } ], "name": "receivedAddr", "type": "event" } ]`
108-
const abiBin = `0x608060405234801561001057600080fd5b506102a0806100206000396000f3fe60806040526004361061003b576000357c010000000000000000000000000000000000000000000000000000000090048063a69b6ed014610040575b600080fd5b6100b76004803603602081101561005657600080fd5b810190808035906020019064010000000081111561007357600080fd5b82018360208201111561008557600080fd5b803590602001918460018302840111640100000000831117156100a757600080fd5b9091929391929390505050610132565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100f75780820151818401526020810190506100dc565b50505050905090810190601f1680156101245780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60607f75fd880d39c1daf53b6547ab6cb59451fc6452d27caa90e5b6649dd8293b9eed33348585604051808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509550505050505060405180910390a17f46923992397eac56cf13058aced2a1871933622717e27b24eabc13bf9dd329c833604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a16040805190810160405280600b81526020017f68656c6c6f20776f726c6400000000000000000000000000000000000000000081525090509291505056fea165627a7a72305820ff0c57dad254cfeda48c9cfb47f1353a558bccb4d1bc31da1dae69315772d29e0029`
109-
const deployedCode = `60806040526004361061003b576000357c010000000000000000000000000000000000000000000000000000000090048063a69b6ed014610040575b600080fd5b6100b76004803603602081101561005657600080fd5b810190808035906020019064010000000081111561007357600080fd5b82018360208201111561008557600080fd5b803590602001918460018302840111640100000000831117156100a757600080fd5b9091929391929390505050610132565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100f75780820151818401526020810190506100dc565b50505050905090810190601f1680156101245780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60607f75fd880d39c1daf53b6547ab6cb59451fc6452d27caa90e5b6649dd8293b9eed33348585604051808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509550505050505060405180910390a17f46923992397eac56cf13058aced2a1871933622717e27b24eabc13bf9dd329c833604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a16040805190810160405280600b81526020017f68656c6c6f20776f726c6400000000000000000000000000000000000000000081525090509291505056fea165627a7a72305820ff0c57dad254cfeda48c9cfb47f1353a558bccb4d1bc31da1dae69315772d29e0029`
107+
const (
108+
abiJSON = `[ { "constant": false, "inputs": [ { "name": "memo", "type": "bytes" } ], "name": "receive", "outputs": [ { "name": "res", "type": "string" } ], "payable": true, "stateMutability": "payable", "type": "function" }, { "anonymous": false, "inputs": [ { "indexed": false, "name": "sender", "type": "address" }, { "indexed": false, "name": "amount", "type": "uint256" }, { "indexed": false, "name": "memo", "type": "bytes" } ], "name": "received", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": false, "name": "sender", "type": "address" } ], "name": "receivedAddr", "type": "event" } ]`
109+
abiBin = `0x608060405234801561001057600080fd5b506102a0806100206000396000f3fe60806040526004361061003b576000357c010000000000000000000000000000000000000000000000000000000090048063a69b6ed014610040575b600080fd5b6100b76004803603602081101561005657600080fd5b810190808035906020019064010000000081111561007357600080fd5b82018360208201111561008557600080fd5b803590602001918460018302840111640100000000831117156100a757600080fd5b9091929391929390505050610132565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100f75780820151818401526020810190506100dc565b50505050905090810190601f1680156101245780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60607f75fd880d39c1daf53b6547ab6cb59451fc6452d27caa90e5b6649dd8293b9eed33348585604051808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509550505050505060405180910390a17f46923992397eac56cf13058aced2a1871933622717e27b24eabc13bf9dd329c833604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a16040805190810160405280600b81526020017f68656c6c6f20776f726c6400000000000000000000000000000000000000000081525090509291505056fea165627a7a72305820ff0c57dad254cfeda48c9cfb47f1353a558bccb4d1bc31da1dae69315772d29e0029`
110+
deployedCode = `60806040526004361061003b576000357c010000000000000000000000000000000000000000000000000000000090048063a69b6ed014610040575b600080fd5b6100b76004803603602081101561005657600080fd5b810190808035906020019064010000000081111561007357600080fd5b82018360208201111561008557600080fd5b803590602001918460018302840111640100000000831117156100a757600080fd5b9091929391929390505050610132565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100f75780820151818401526020810190506100dc565b50505050905090810190601f1680156101245780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60607f75fd880d39c1daf53b6547ab6cb59451fc6452d27caa90e5b6649dd8293b9eed33348585604051808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509550505050505060405180910390a17f46923992397eac56cf13058aced2a1871933622717e27b24eabc13bf9dd329c833604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a16040805190810160405280600b81526020017f68656c6c6f20776f726c6400000000000000000000000000000000000000000081525090509291505056fea165627a7a72305820ff0c57dad254cfeda48c9cfb47f1353a558bccb4d1bc31da1dae69315772d29e0029`
111+
)
110112

111113
// expected return value contains "hello world"
112114
var expectedReturn = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
@@ -125,12 +127,12 @@ func TestNewSimulatedBackend(t *testing.T) {
125127
sim := simTestBackend(testAddr)
126128
defer sim.Close()
127129

128-
if sim.config != params.AllEthashProtocolChanges {
129-
t.Errorf("expected sim config to equal params.AllEthashProtocolChanges, got %v", sim.config)
130+
if sim.config != params.AllXHashProtocolChanges {
131+
t.Errorf("expected sim config to equal params.AllXHashProtocolChanges, got %v", sim.config)
130132
}
131133

132-
if sim.blockchain.Config() != params.AllEthashProtocolChanges {
133-
t.Errorf("expected sim blockchain config to equal params.AllEthashProtocolChanges, got %v", sim.config)
134+
if sim.blockchain.Config() != params.AllXHashProtocolChanges {
135+
t.Errorf("expected sim blockchain config to equal params.AllXHashProtocolChanges, got %v", sim.config)
134136
}
135137

136138
stateDB, _ := sim.blockchain.State()
@@ -395,7 +397,7 @@ func TestEstimateGas(t *testing.T) {
395397
contractAddr, _, _, _ := bind.DeployContract(opts, parsed, common.FromHex(contractBin), sim)
396398
sim.Commit()
397399

398-
var cases = []struct {
400+
cases := []struct {
399401
name string
400402
message parallax.CallMsg
401403
expect uint64
@@ -497,7 +499,7 @@ func TestEstimateGasWithPrice(t *testing.T) {
497499
defer sim.Close()
498500

499501
recipient := common.HexToAddress("deadbeef")
500-
var cases = []struct {
502+
cases := []struct {
501503
name string
502504
message parallax.CallMsg
503505
expect uint64

build/update-license.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ var (
6767
"cmd/internal/browser",
6868
"common/bitutil/bitutil",
6969
"common/prque/",
70-
"consensus/ethash/xor.go",
70+
"consensus/xhash/xor.go",
7171
"crypto/blake2b/",
7272
"crypto/bn256/",
7373
"crypto/bls12381/",

circle.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ machine:
44

55
dependencies:
66
cache_directories:
7-
- "~/.ethash" # Cache the ethash DAG generated by hive for consecutive builds
7+
- "~/.xhash" # Cache the xhash DAG generated by hive for consecutive builds
88
- "~/.docker" # Cache all docker images manually to avoid lengthy rebuilds
99
override:
1010
# Restore all previously cached docker images
1111
- mkdir -p ~/.docker
1212
- for img in `ls ~/.docker`; do docker load -i ~/.docker/$img; done
1313

14-
# Pull in and hive, restore cached ethash DAGs and do a dry run
14+
# Pull in and hive, restore cached xhash DAGs and do a dry run
1515
- go get -u github.com/karalabe/hive
16-
- (cd ~/.go_workspace/src/github.com/karalabe/hive && mkdir -p workspace/ethash/ ~/.ethash)
17-
- (cd ~/.go_workspace/src/github.com/karalabe/hive && cp -r ~/.ethash/. workspace/ethash/)
16+
- (cd ~/.go_workspace/src/github.com/karalabe/hive && mkdir -p workspace/xhash/ ~/.xhash)
17+
- (cd ~/.go_workspace/src/github.com/karalabe/hive && cp -r ~/.xhash/. workspace/xhash/)
1818
- (cd ~/.go_workspace/src/github.com/karalabe/hive && hive --docker-noshell --client=NONE --test=. --sim=. --loglevel=6)
1919

20-
# Cache all the docker images and the ethash DAGs
20+
# Cache all the docker images and the xhash DAGs
2121
- for img in `docker images | grep -v "^<none>" | tail -n +2 | awk '{print $1}'`; do docker save $img > ~/.docker/`echo $img | tr '/' ':'`.tar; done
22-
- cp -r ~/.go_workspace/src/github.com/karalabe/hive/workspace/ethash/. ~/.ethash
22+
- cp -r ~/.go_workspace/src/github.com/karalabe/hive/workspace/xhash/. ~/.xhash
2323

2424
test:
2525
override:
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
{
2-
"config": {
3-
"chainId": 19763,
4-
"homesteadBlock": 0,
5-
"eip150Block": 0,
6-
"eip155Block": 0,
7-
"eip158Block": 0,
8-
"byzantiumBlock": 0,
9-
"ethash": {}
10-
},
11-
"nonce": "0xdeadbeefdeadbeef",
12-
"timestamp": "0x0",
13-
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
14-
"gasLimit": "0x80000000",
15-
"difficulty": "0x20000",
16-
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
17-
"coinbase": "0x0000000000000000000000000000000000000000",
18-
"alloc": {
19-
"71562b71999873db5b286df957af199ec94617f7": {
20-
"balance": "0xffffffffffffffffffffffffff"
21-
}
22-
},
23-
"number": "0x0",
24-
"gasUsed": "0x0",
25-
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
2+
"config": {
3+
"chainId": 19763,
4+
"homesteadBlock": 0,
5+
"eip150Block": 0,
6+
"eip155Block": 0,
7+
"eip158Block": 0,
8+
"byzantiumBlock": 0,
9+
"xhash": {}
10+
},
11+
"nonce": "0xdeadbeefdeadbeef",
12+
"timestamp": "0x0",
13+
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
14+
"gasLimit": "0x80000000",
15+
"difficulty": "0x20000",
16+
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
17+
"coinbase": "0x0000000000000000000000000000000000000000",
18+
"alloc": {
19+
"71562b71999873db5b286df957af199ec94617f7": {
20+
"balance": "0xffffffffffffffffffffffffff"
21+
}
22+
},
23+
"number": "0x0",
24+
"gasUsed": "0x0",
25+
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
2626
}

0 commit comments

Comments
 (0)