mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-15 17:30:44 +00:00
Hot_Fix Bad block Error
This commit is contained in:
parent
3456368fdc
commit
3e5f4d54a8
22 changed files with 331 additions and 74 deletions
6
.github/CONTRIBUTING.md
vendored
6
.github/CONTRIBUTING.md
vendored
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
Before you do a feature request please check and make sure that it isn't possible
|
Before you do a feature request please check and make sure that it isn't possible
|
||||||
through some other means. The JavaScript enabled console is a powerful feature
|
through some other means. The JavaScript enabled console is a powerful feature
|
||||||
in the right hands.
|
in the right hands. Please check our [Wiki page](https://github.com/ethereum/go-ethereum/wiki) for more info
|
||||||
|
and help.
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
|
@ -10,3 +11,6 @@ If you'd like to contribute to go-ethereum please fork, fix, commit and
|
||||||
send a pull request. Commits which do not comply with the coding standards
|
send a pull request. Commits which do not comply with the coding standards
|
||||||
are ignored (use gofmt!).
|
are ignored (use gofmt!).
|
||||||
|
|
||||||
|
See [Developers' Guide](https://github.com/ethereum/go-ethereum/wiki/Developers'-Guide)
|
||||||
|
for more details on configuring your environment, testing, and
|
||||||
|
dependency management.
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,17 @@ FROM golang:1.10-alpine as builder
|
||||||
|
|
||||||
RUN apk add --no-cache make gcc musl-dev linux-headers
|
RUN apk add --no-cache make gcc musl-dev linux-headers
|
||||||
|
|
||||||
ADD . /XDChain
|
ADD . /XDCchain
|
||||||
|
|
||||||
RUN cd /XDChain \
|
RUN cd /XDCchain \
|
||||||
&& make XDC\
|
&& make XDC \
|
||||||
&& chmod +x /XDCchain/build/bin/XDC
|
&& chmod +x /XDCchain/build/bin/XDC
|
||||||
|
|
||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
|
|
||||||
LABEL maintainer="anil@xinfin.org"
|
LABEL maintainer="anil@xinfin.org"
|
||||||
|
|
||||||
WORKDIR /XDChain
|
WORKDIR /XDCchain
|
||||||
|
|
||||||
COPY --from=builder /XDCchain/build/bin/XDC /usr/local/bin/XDC
|
COPY --from=builder /XDCchain/build/bin/XDC /usr/local/bin/XDC
|
||||||
|
|
||||||
|
|
@ -31,7 +31,7 @@ ENV ANNOUNCE_TXS ''
|
||||||
|
|
||||||
RUN apk add --no-cache ca-certificates
|
RUN apk add --no-cache ca-certificates
|
||||||
|
|
||||||
COPY docker/XDChain ./
|
COPY docker/XDCchain ./
|
||||||
COPY genesis/ ./
|
COPY genesis/ ./
|
||||||
|
|
||||||
EXPOSE 8545 8546 30303 30303/udp
|
EXPOSE 8545 8546 30303 30303/udp
|
||||||
|
|
|
||||||
5
Makefile
5
Makefile
|
|
@ -15,6 +15,11 @@ XDC:
|
||||||
@echo "Done building."
|
@echo "Done building."
|
||||||
@echo "Run \"$(GOBIN)/XDC\" to launch XDC."
|
@echo "Run \"$(GOBIN)/XDC\" to launch XDC."
|
||||||
|
|
||||||
|
gc:
|
||||||
|
build/env.sh go run build/ci.go install ./cmd/gc
|
||||||
|
@echo "Done building."
|
||||||
|
@echo "Run \"$(GOBIN)/gc\" to launch gc."
|
||||||
|
|
||||||
bootnode:
|
bootnode:
|
||||||
build/env.sh go run build/ci.go install ./cmd/bootnode
|
build/env.sh go run build/ci.go install ./cmd/bootnode
|
||||||
@echo "Done building."
|
@echo "Done building."
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,13 @@ package main
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"runtime"
|
||||||
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
|
|
@ -14,17 +21,18 @@ import (
|
||||||
"github.com/hashicorp/golang-lru"
|
"github.com/hashicorp/golang-lru"
|
||||||
"github.com/syndtr/goleveldb/leveldb"
|
"github.com/syndtr/goleveldb/leveldb"
|
||||||
"github.com/syndtr/goleveldb/leveldb/util"
|
"github.com/syndtr/goleveldb/leveldb/util"
|
||||||
"os"
|
|
||||||
"os/signal"
|
|
||||||
"runtime"
|
|
||||||
"sync"
|
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
dir = flag.String("dir", "", "dir to mainet chain data")
|
dir = flag.String("dir", "", "directory to XDCChain chaindata")
|
||||||
cacheSize = flag.Int("size", 1000000, "dir to mainet chain data")
|
cacheSize = flag.Int("size", 1000000, "LRU cache size")
|
||||||
|
sercureKey = []byte("secure-key-")
|
||||||
|
nWorker = runtime.NumCPU() / 2
|
||||||
|
cleanAddress = []common.Address{common.HexToAddress(common.BlockSigners)}
|
||||||
|
cache *lru.Cache
|
||||||
|
finish = int32(0)
|
||||||
|
running = true
|
||||||
|
stateRoots = make(chan TrieRoot)
|
||||||
)
|
)
|
||||||
|
|
||||||
type TrieRoot struct {
|
type TrieRoot struct {
|
||||||
|
|
@ -42,14 +50,6 @@ type ResultProcessNode struct {
|
||||||
keys [17]*[]byte
|
keys [17]*[]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
var sercureKey = []byte("secure-key-")
|
|
||||||
var nWorker = runtime.NumCPU() / 2
|
|
||||||
var cleanAddress = []common.Address{common.HexToAddress(common.BlockSigners)}
|
|
||||||
var cache *lru.Cache
|
|
||||||
var finish = int32(0)
|
|
||||||
var running = true
|
|
||||||
var stateRoots = make(chan TrieRoot)
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
lddb, _ := ethdb.NewLDBDatabase(*dir, eth.DefaultConfig.DatabaseCache, utils.MakeDatabaseHandles())
|
lddb, _ := ethdb.NewLDBDatabase(*dir, eth.DefaultConfig.DatabaseCache, utils.MakeDatabaseHandles())
|
||||||
|
|
@ -122,8 +122,8 @@ func (w *wizard) makeGenesis() {
|
||||||
genesis.Config.XDPoS.Period = uint64(w.readDefaultInt(2))
|
genesis.Config.XDPoS.Period = uint64(w.readDefaultInt(2))
|
||||||
|
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Println("How many XDC should be rewarded to masternode? (default = 100)")
|
fmt.Println("How many XDC should be rewarded to masternode? (default = 350)")
|
||||||
genesis.Config.XDPoS.Reward = uint64(w.readDefaultInt(100))
|
genesis.Config.XDPoS.Reward = uint64(w.readDefaultInt(350))
|
||||||
|
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Println("Who own the first masternodes? (mandatory)")
|
fmt.Println("Who own the first masternodes? (mandatory)")
|
||||||
|
|
@ -231,8 +231,8 @@ func (w *wizard) makeGenesis() {
|
||||||
code, _ = contractBackend.CodeAt(ctx, multiSignWalletAddr, nil)
|
code, _ = contractBackend.CodeAt(ctx, multiSignWalletAddr, nil)
|
||||||
storage = make(map[common.Hash]common.Hash)
|
storage = make(map[common.Hash]common.Hash)
|
||||||
contractBackend.ForEachStorageAt(ctx, multiSignWalletAddr, nil, f)
|
contractBackend.ForEachStorageAt(ctx, multiSignWalletAddr, nil, f)
|
||||||
fBalance := big.NewInt(0) // 16m
|
fBalance := big.NewInt(0) // 3 billion
|
||||||
fBalance.Add(fBalance, big.NewInt(16*1000*1000))
|
fBalance.Add(fBalance, big.NewInt(3*1000*1000*1000))
|
||||||
fBalance.Mul(fBalance, big.NewInt(1000000000000000000))
|
fBalance.Mul(fBalance, big.NewInt(1000000000000000000))
|
||||||
genesis.Alloc[common.HexToAddress(common.FoudationAddr)] = core.GenesisAccount{
|
genesis.Alloc[common.HexToAddress(common.FoudationAddr)] = core.GenesisAccount{
|
||||||
Balance: fBalance,
|
Balance: fBalance,
|
||||||
|
|
@ -298,24 +298,24 @@ func (w *wizard) makeGenesis() {
|
||||||
storage = make(map[common.Hash]common.Hash)
|
storage = make(map[common.Hash]common.Hash)
|
||||||
contractBackend.ForEachStorageAt(ctx, multiSignWalletTeamAddr, nil, f)
|
contractBackend.ForEachStorageAt(ctx, multiSignWalletTeamAddr, nil, f)
|
||||||
// Team balance.
|
// Team balance.
|
||||||
balance := big.NewInt(0) // 12m
|
balance := big.NewInt(0) // 20 billion
|
||||||
balance.Add(balance, big.NewInt(12*1000*1000))
|
balance.Add(balance, big.NewInt(20*1000*1000*1000))
|
||||||
balance.Mul(balance, big.NewInt(1000000000000000000))
|
balance.Mul(balance, big.NewInt(1000000000000000000))
|
||||||
subBalance := big.NewInt(0) // i * 50k
|
subBalance := big.NewInt(0) // i * 50k
|
||||||
subBalance.Add(subBalance, big.NewInt(int64(len(signers))*50*1000))
|
subBalance.Add(subBalance, big.NewInt(int64(len(signers))*50*1000))
|
||||||
subBalance.Mul(subBalance, big.NewInt(1000000000000000000))
|
subBalance.Mul(subBalance, big.NewInt(1000000000000000000))
|
||||||
balance.Sub(balance, subBalance) // 12m - i * 50k
|
balance.Sub(balance, subBalance) // 12m - i * 50k
|
||||||
genesis.Alloc[common.HexToAddress(common.TeamAddr)] = core.GenesisAccount{
|
genesis.Alloc[common.HexToAddress(common.TeamAddr)] = core.GenesisAccount{
|
||||||
Balance: balance,
|
Balance: balance,
|
||||||
Code: code,
|
Code: code,
|
||||||
Storage: storage,
|
Storage: storage,
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Println("What is swap wallet address for fund 55m XDC?")
|
fmt.Println("What is swap wallet address for fund 14.5Billion XDC?")
|
||||||
swapAddr := *w.readAddress()
|
swapAddr := *w.readAddress()
|
||||||
baseBalance := big.NewInt(0) // 55m
|
baseBalance := big.NewInt(0) // 14.5Billion
|
||||||
baseBalance.Add(baseBalance, big.NewInt(55*1000*1000))
|
baseBalance.Add(baseBalance, big.NewInt(145*1000*1000*100))
|
||||||
baseBalance.Mul(baseBalance, big.NewInt(1000000000000000000))
|
baseBalance.Mul(baseBalance, big.NewInt(1000000000000000000))
|
||||||
genesis.Alloc[swapAddr] = core.GenesisAccount{
|
genesis.Alloc[swapAddr] = core.GenesisAccount{
|
||||||
Balance: baseBalance,
|
Balance: baseBalance,
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ import (
|
||||||
"math/big"
|
"math/big"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"reflect"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -424,9 +426,11 @@ func (c *XDPoS) verifyCascadingFields(chain consensus.ChainReader, header *types
|
||||||
signers = RemovePenaltiesFromBlock(chain, signers, number-uint64(i)*c.config.Epoch)
|
signers = RemovePenaltiesFromBlock(chain, signers, number-uint64(i)*c.config.Epoch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
byteMasterNodes := common.ExtractAddressToBytes(signers)
|
|
||||||
extraSuffix := len(header.Extra) - extraSeal
|
extraSuffix := len(header.Extra) - extraSeal
|
||||||
if !bytes.Equal(header.Extra[extraVanity:extraSuffix], byteMasterNodes) {
|
masternodesFromCheckpointHeader := common.ExtractAddressFromBytes(header.Extra[extraVanity:extraSuffix])
|
||||||
|
validSigners := compareSignersLists(masternodesFromCheckpointHeader, signers)
|
||||||
|
if !validSigners {
|
||||||
|
log.Error("Masternodes lists are different in checkpoint header and snapshot", "number", number, "masternodes_from_checkpoint_header", masternodesFromCheckpointHeader, "masternodes_in_snapshot", signers, "penList", penPenalties)
|
||||||
return errInvalidCheckpointSigners
|
return errInvalidCheckpointSigners
|
||||||
}
|
}
|
||||||
if c.HookVerifyMNs != nil {
|
if c.HookVerifyMNs != nil {
|
||||||
|
|
@ -440,6 +444,21 @@ func (c *XDPoS) verifyCascadingFields(chain consensus.ChainReader, header *types
|
||||||
return c.verifySeal(chain, header, parents, fullVerify)
|
return c.verifySeal(chain, header, parents, fullVerify)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// compare 2 signers lists
|
||||||
|
// return true if they are same elements, otherwise return false
|
||||||
|
func compareSignersLists(list1 []common.Address, list2 []common.Address) bool {
|
||||||
|
if len(list1) == 0 && len(list2) == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
sort.Slice(list1, func(i, j int) bool {
|
||||||
|
return list1[i].String() <= list1[j].String()
|
||||||
|
})
|
||||||
|
sort.Slice(list2, func(i, j int) bool {
|
||||||
|
return list2[i].String() <= list2[j].String()
|
||||||
|
})
|
||||||
|
return reflect.DeepEqual(list1, list2)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *XDPoS) GetSnapshot(chain consensus.ChainReader, header *types.Header) (*Snapshot, error) {
|
func (c *XDPoS) GetSnapshot(chain consensus.ChainReader, header *types.Header) (*Snapshot, error) {
|
||||||
number := header.Number.Uint64()
|
number := header.Number.Uint64()
|
||||||
log.Trace("take snapshot", "number", number, "hash", header.Hash())
|
log.Trace("take snapshot", "number", number, "hash", header.Hash())
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ func TestGetM1M2FromCheckpointHeader(t *testing.T) {
|
||||||
Epoch: uint64(epoch),
|
Epoch: uint64(epoch),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
testMoveM2 := []uint64{0,0,0,1,1,1,2,2,2,0,0,0,1,1,1,2,2,2}
|
testMoveM2 := []uint64{0, 0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 0, 1, 1, 1, 2, 2, 2}
|
||||||
//try from block 3410001 to 3410018
|
//try from block 3410001 to 3410018
|
||||||
for i := uint64(3464001); i <= 3464018; i++ {
|
for i := uint64(3464001); i <= 3464018; i++ {
|
||||||
currentNumber := int64(i)
|
currentNumber := int64(i)
|
||||||
|
|
@ -47,3 +47,38 @@ func TestGetM1M2FromCheckpointHeader(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCompareSignersLists(t *testing.T) {
|
||||||
|
list1 := []common.Address{
|
||||||
|
common.StringToAddress("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
|
||||||
|
common.StringToAddress("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"),
|
||||||
|
common.StringToAddress("cccccccccccccccccccccccccccccccccccccccc"),
|
||||||
|
common.StringToAddress("dddddddddddddddddddddddddddddddddddddddd"),
|
||||||
|
}
|
||||||
|
list2 := []common.Address{
|
||||||
|
common.StringToAddress("cccccccccccccccccccccccccccccccccccccccc"),
|
||||||
|
common.StringToAddress("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
|
||||||
|
common.StringToAddress("dddddddddddddddddddddddddddddddddddddddd"),
|
||||||
|
common.StringToAddress("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"),
|
||||||
|
}
|
||||||
|
list3 := []common.Address{
|
||||||
|
common.StringToAddress("cccccccccccccccccccccccccccccccccccccccc"),
|
||||||
|
common.StringToAddress("dddddddddddddddddddddddddddddddddddddddd"),
|
||||||
|
common.StringToAddress("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"),
|
||||||
|
}
|
||||||
|
if !compareSignersLists(list1, list2) {
|
||||||
|
t.Error("list1 should be equal to list2", "list1", list1, "list2", list2)
|
||||||
|
}
|
||||||
|
if compareSignersLists(list1, list3) {
|
||||||
|
t.Error("list1 and list3 should not be same", "list1", list1, "list3", list3)
|
||||||
|
}
|
||||||
|
if !compareSignersLists([]common.Address{}, []common.Address{}) {
|
||||||
|
t.Error("Failed with empty list")
|
||||||
|
}
|
||||||
|
if !compareSignersLists([]common.Address{common.StringToAddress("cccccccccccccccccccccccccccccccccccccccc")}, []common.Address{common.StringToAddress("cccccccccccccccccccccccccccccccccccccccc")}) {
|
||||||
|
t.Error("Failed with list has only one signer")
|
||||||
|
}
|
||||||
|
if compareSignersLists([]common.Address{common.StringToAddress("aaaaaaaaaaaaaaaa")}, []common.Address{common.StringToAddress("cccccccccccccccccccccccccccccccccccccccc")}) {
|
||||||
|
t.Error("Failed with list has only one signer")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ package contracts
|
||||||
// "randomSecret": 0,
|
// "randomSecret": 0,
|
||||||
// "randomOpening": 1,
|
// "randomOpening": 1,
|
||||||
// }
|
// }
|
||||||
// datadir = "/mnt/sgp1_tuna_chaindata3/data/XDCchaindata"
|
// datadir = "/mnt/sgp1_tuna_chaindata3/data/XDC/chaindata"
|
||||||
// candidate = "0xd6fa3e7a89bf8c84f0ccd204a15c0d259daf2091"
|
// candidate = "0xd6fa3e7a89bf8c84f0ccd204a15c0d259daf2091"
|
||||||
//)
|
//)
|
||||||
//
|
//
|
||||||
|
|
|
||||||
|
|
@ -464,7 +464,7 @@ func GetRewardBalancesRate(foundationWalletAddr common.Address, state *state.Sta
|
||||||
log.Error("Fail to parse json holders", "error", err)
|
log.Error("Fail to parse json holders", "error", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
log.Info("Holders reward", "holders", string(jsonHolders), "master node", masterAddr.String())
|
log.Trace("Holders reward", "holders", string(jsonHolders), "masternode", masterAddr.String())
|
||||||
|
|
||||||
return balances, nil
|
return balances, nil
|
||||||
}
|
}
|
||||||
|
|
@ -503,7 +503,8 @@ func Encrypt(key []byte, text string) string {
|
||||||
|
|
||||||
block, err := aes.NewCipher(key)
|
block, err := aes.NewCipher(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Error("Fail to encrypt", "err", err)
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// The IV needs to be unique, but not secure. Therefore it's common to
|
// The IV needs to be unique, but not secure. Therefore it's common to
|
||||||
|
|
@ -511,7 +512,8 @@ func Encrypt(key []byte, text string) string {
|
||||||
ciphertext := make([]byte, aes.BlockSize+len(plaintext))
|
ciphertext := make([]byte, aes.BlockSize+len(plaintext))
|
||||||
iv := ciphertext[:aes.BlockSize]
|
iv := ciphertext[:aes.BlockSize]
|
||||||
if _, err := io.ReadFull(cryptoRand.Reader, iv); err != nil {
|
if _, err := io.ReadFull(cryptoRand.Reader, iv); err != nil {
|
||||||
panic(err)
|
log.Error("Fail to encrypt iv", "err", err)
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
stream := cipher.NewCFBEncrypter(block, iv)
|
stream := cipher.NewCFBEncrypter(block, iv)
|
||||||
|
|
@ -527,13 +529,15 @@ func Decrypt(key []byte, cryptoText string) string {
|
||||||
|
|
||||||
block, err := aes.NewCipher(key)
|
block, err := aes.NewCipher(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Error("Fail to decrypt", "err", err)
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// The IV needs to be unique, but not secure. Therefore it's common to
|
// The IV needs to be unique, but not secure. Therefore it's common to
|
||||||
// include it at the beginning of the ciphertext.
|
// include it at the beginning of the ciphertext.
|
||||||
if len(ciphertext) < aes.BlockSize {
|
if len(ciphertext) < aes.BlockSize {
|
||||||
panic("ciphertext too short")
|
log.Error("ciphertext too short")
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
iv := ciphertext[:aes.BlockSize]
|
iv := ciphertext[:aes.BlockSize]
|
||||||
ciphertext = ciphertext[aes.BlockSize:]
|
ciphertext = ciphertext[aes.BlockSize:]
|
||||||
|
|
|
||||||
|
|
@ -177,7 +177,7 @@ func TestRewardBalance(t *testing.T) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetRewardBalancesRate(foudationWalletAddr common.Address, masterAddr common.Address, totalReward *big.Int, validator *contractValidator.XDCValidator) (map[common.Address]*big.Int, error) {
|
func GetRewardBalancesRate(foudationWalletAddr common.Address, masterAddr common.Address, totalReward *big.Int, validator *contractValidator.XDCalidator) (map[common.Address]*big.Int, error) {
|
||||||
owner := GetCandidatesOwnerBySigner(validator, masterAddr)
|
owner := GetCandidatesOwnerBySigner(validator, masterAddr)
|
||||||
balances := make(map[common.Address]*big.Int)
|
balances := make(map[common.Address]*big.Int)
|
||||||
rewardMaster := new(big.Int).Mul(totalReward, new(big.Int).SetInt64(common.RewardMasterPercent))
|
rewardMaster := new(big.Int).Mul(totalReward, new(big.Int).SetInt64(common.RewardMasterPercent))
|
||||||
|
|
|
||||||
191
docker/XDCchain/entrypoint.sh
Normal file
191
docker/XDCchain/entrypoint.sh
Normal file
|
|
@ -0,0 +1,191 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# vars from docker env
|
||||||
|
# - IDENTITY (default to empty)
|
||||||
|
# - PASSWORD (default to empty)
|
||||||
|
# - PRIVATE_KEY (default to empty)
|
||||||
|
# - BOOTNODES (default to empty)
|
||||||
|
# - EXTIP (default to empty)
|
||||||
|
# - VERBOSITY (default to 3)
|
||||||
|
# - MAXPEERS (default to 25)
|
||||||
|
# - SYNC_MODE (default to 'full')
|
||||||
|
# - NETWORK_ID (default to '89')
|
||||||
|
# - WS_SECRET (default to empty)
|
||||||
|
# - NETSTATS_HOST (default to 'netstats-server:3000')
|
||||||
|
# - NETSTATS_PORT (default to 'netstats-server:3000')
|
||||||
|
|
||||||
|
# constants
|
||||||
|
DATA_DIR="data"
|
||||||
|
KEYSTORE_DIR="keystore"
|
||||||
|
|
||||||
|
# variables
|
||||||
|
genesisPath=""
|
||||||
|
params=""
|
||||||
|
accountsCount=$(
|
||||||
|
XDC account list --datadir $DATA_DIR --keystore $KEYSTORE_DIR \
|
||||||
|
2> /dev/null \
|
||||||
|
| wc -l
|
||||||
|
)
|
||||||
|
|
||||||
|
# file to env
|
||||||
|
for env in IDENTITY PASSWORD PRIVATE_KEY BOOTNODES WS_SECRET NETSTATS_HOST \
|
||||||
|
NETSTATS_PORT EXTIP SYNC_MODE NETWORK_ID ANNOUNCE_TXS STORE_REWARD DEBUG_MODE MAXPEERS; do
|
||||||
|
file=$(eval echo "\$${env}_FILE")
|
||||||
|
if [[ -f $file ]] && [[ ! -z $file ]]; then
|
||||||
|
echo "Replacing $env by $file"
|
||||||
|
export $env=$(cat $file)
|
||||||
|
elif [[ "$env" == "BOOTNODES" ]] && [[ ! -z $file ]]; then
|
||||||
|
echo "Bootnodes file is not available. Waiting for it to be provisioned..."
|
||||||
|
while true ; do
|
||||||
|
if [[ -f $file ]] && [[ $(grep -e enode $file) ]]; then
|
||||||
|
echo "Fount bootnode file."
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
echo "Still no bootnodes file, sleeping..."
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
|
export $env=$(cat $file)
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# networkid
|
||||||
|
if [[ ! -z $NETWORK_ID ]]; then
|
||||||
|
case $NETWORK_ID in
|
||||||
|
88 )
|
||||||
|
genesisPath="mainnet.json"
|
||||||
|
;;
|
||||||
|
89 )
|
||||||
|
genesisPath="testnet.json"
|
||||||
|
params="$params --XDC-testnet --gcmode archive --rpcapi db,eth,net,web3,personal,debug"
|
||||||
|
;;
|
||||||
|
90 )
|
||||||
|
genesisPath="devnet.json"
|
||||||
|
;;
|
||||||
|
* )
|
||||||
|
echo "network id not supported"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
params="$params --networkid $NETWORK_ID"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# data dir
|
||||||
|
if [[ ! -d $DATA_DIR/XDC ]]; then
|
||||||
|
echo "No blockchain data, creating genesis block."
|
||||||
|
XDC init $genesisPath --datadir $DATA_DIR 2> /dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
# identity
|
||||||
|
if [[ -z $IDENTITY ]]; then
|
||||||
|
IDENTITY="unnamed_$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# password file
|
||||||
|
if [[ ! -f ./password ]]; then
|
||||||
|
if [[ ! -z $PASSWORD ]]; then
|
||||||
|
echo "Password env is set. Writing into file."
|
||||||
|
echo "$PASSWORD" > ./password
|
||||||
|
else
|
||||||
|
echo "No password set (or empty), generating a new one"
|
||||||
|
$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32} > password)
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# private key
|
||||||
|
if [[ $accountsCount -le 0 ]]; then
|
||||||
|
echo "No accounts found"
|
||||||
|
if [[ ! -z $PRIVATE_KEY ]]; then
|
||||||
|
echo "Creating account from private key"
|
||||||
|
echo "$PRIVATE_KEY" > ./private_key
|
||||||
|
XDC account import ./private_key \
|
||||||
|
--datadir $DATA_DIR \
|
||||||
|
--keystore $KEYSTORE_DIR \
|
||||||
|
--password ./password
|
||||||
|
rm ./private_key
|
||||||
|
else
|
||||||
|
echo "Creating new account"
|
||||||
|
XDC account new \
|
||||||
|
--datadir $DATA_DIR \
|
||||||
|
--keystore $KEYSTORE_DIR \
|
||||||
|
--password ./password
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
account=$(
|
||||||
|
XDC account list --datadir $DATA_DIR --keystore $KEYSTORE_DIR \
|
||||||
|
2> /dev/null \
|
||||||
|
| head -n 1 \
|
||||||
|
| cut -d"{" -f 2 | cut -d"}" -f 1
|
||||||
|
)
|
||||||
|
echo "Using account $account"
|
||||||
|
params="$params --unlock $account"
|
||||||
|
|
||||||
|
# bootnodes
|
||||||
|
if [[ ! -z $BOOTNODES ]]; then
|
||||||
|
params="$params --bootnodes $BOOTNODES"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# extip
|
||||||
|
if [[ ! -z $EXTIP ]]; then
|
||||||
|
params="$params --nat extip:${EXTIP}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# syncmode
|
||||||
|
if [[ ! -z $SYNC_MODE ]]; then
|
||||||
|
params="$params --syncmode ${SYNC_MODE}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# netstats
|
||||||
|
if [[ ! -z $WS_SECRET ]]; then
|
||||||
|
echo "Will report to netstats server ${NETSTATS_HOST}:${NETSTATS_PORT}"
|
||||||
|
params="$params --ethstats ${IDENTITY}:${WS_SECRET}@${NETSTATS_HOST}:${NETSTATS_PORT}"
|
||||||
|
else
|
||||||
|
echo "WS_SECRET not set, will not report to netstats server."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# annonce txs
|
||||||
|
if [[ ! -z $ANNOUNCE_TXS ]]; then
|
||||||
|
params="$params --announce-txs"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# store reward
|
||||||
|
if [[ ! -z $STORE_REWARD ]]; then
|
||||||
|
params="$params --store-reward"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# debug mode
|
||||||
|
if [[ ! -z $DEBUG_MODE ]]; then
|
||||||
|
params="$params --gcmode archive --rpcapi db,eth,net,web3,personal,debug"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# maxpeers
|
||||||
|
if [[ -z $MAXPEERS ]]; then
|
||||||
|
MAXPEERS=25
|
||||||
|
fi
|
||||||
|
|
||||||
|
# dump
|
||||||
|
echo "dump: $IDENTITY $account $BOOTNODES"
|
||||||
|
|
||||||
|
set -x
|
||||||
|
|
||||||
|
exec XDC $params \
|
||||||
|
--verbosity $VERBOSITY \
|
||||||
|
--datadir $DATA_DIR \
|
||||||
|
--keystore $KEYSTORE_DIR \
|
||||||
|
--identity $IDENTITY \
|
||||||
|
--maxpeers $MAXPEERS \
|
||||||
|
--password ./password \
|
||||||
|
--port 30303 \
|
||||||
|
--txpool.globalqueue 5000 \
|
||||||
|
--txpool.globalslots 5000 \
|
||||||
|
--rpc \
|
||||||
|
--rpccorsdomain "*" \
|
||||||
|
--rpcaddr 0.0.0.0 \
|
||||||
|
--rpcport 8545 \
|
||||||
|
--rpcvhosts "*" \
|
||||||
|
--ws \
|
||||||
|
--wsaddr 0.0.0.0 \
|
||||||
|
--wsport 8546 \
|
||||||
|
--wsorigins "*" \
|
||||||
|
--mine \
|
||||||
|
--gasprice "250000000" \
|
||||||
|
--targetgaslimit "84000000" \
|
||||||
|
"$@"
|
||||||
|
|
@ -423,7 +423,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
||||||
return penalties, nil
|
return penalties, nil
|
||||||
}
|
}
|
||||||
return penComebacks, nil
|
return penComebacks, nil
|
||||||
}
|
}
|
||||||
return []common.Address{}, nil
|
return []common.Address{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -422,7 +422,7 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td *big.I
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
|
|
||||||
// Look up the sync boundaries: the common ancestor and the target block
|
// Look up the sync boundaries: the common ancestor and the target block
|
||||||
latest, err := d.fetchHeight(p,hash)
|
latest, err := d.fetchHeight(p, hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -541,7 +541,7 @@ func (d *Downloader) Terminate() {
|
||||||
|
|
||||||
// fetchHeight retrieves the head header of the remote peer to aid in estimating
|
// fetchHeight retrieves the head header of the remote peer to aid in estimating
|
||||||
// the total time a pending synchronisation would take.
|
// the total time a pending synchronisation would take.
|
||||||
func (d *Downloader) fetchHeight(p *peerConnection,hash common.Hash) (*types.Header, error) {
|
func (d *Downloader) fetchHeight(p *peerConnection, hash common.Hash) (*types.Header, error) {
|
||||||
|
|
||||||
// Request the advertised remote head block and wait for the response
|
// Request the advertised remote head block and wait for the response
|
||||||
go p.peer.RequestHeadersByHash(hash, 1, 0, false)
|
go p.peer.RequestHeadersByHash(hash, 1, 0, false)
|
||||||
|
|
|
||||||
|
|
@ -542,9 +542,9 @@ func hasXDCPrefix(str string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeAddress(s string) (common.Address, error) {
|
func decodeAddress(s string) (common.Address, error) {
|
||||||
if hasXDCPrefix(s) {
|
if hasXDCPrefix(s) {
|
||||||
s = "0x" + s[3:]
|
s = "0x" + s[3:]
|
||||||
}
|
}
|
||||||
b, err := hexutil.Decode(s)
|
b, err := hexutil.Decode(s)
|
||||||
if err == nil && len(b) != common.AddressLength {
|
if err == nil && len(b) != common.AddressLength {
|
||||||
err = fmt.Errorf("hex has invalid length %d after decoding", len(b))
|
err = fmt.Errorf("hex has invalid length %d after decoding", len(b))
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nonce": "0x0",
|
"nonce": "0x0",
|
||||||
"timestamp": "0x5c107ff8",
|
"timestamp": "0x5c1358f5",
|
||||||
"extraData": "0x00000000000000000000000000000000000000000000000000000000000000001b82c4bf317fcafe3d77e8b444c82715d216afe845b7bd987fa22c9bac89b71f0ded03f6e150ba31ad670b2b166684657ffff95f4810380ae7381e9bce41231d5dd8cdd7499e418b648c00af75d184a2f9aba09a6fa4a46fb1a6a3919b027d9cac5aa6890000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
"extraData": "0x00000000000000000000000000000000000000000000000000000000000000001b82c4bf317fcafe3d77e8b444c82715d216afe845b7bd987fa22c9bac89b71f0ded03f6e150ba31ad670b2b166684657ffff95f4810380ae7381e9bce41231d5dd8cdd7499e418b648c00af75d184a2f9aba09a6fa4a46fb1a6a3919b027d9cac5aa6890000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||||
"gasLimit": "0x47b760",
|
"gasLimit": "0x47b760",
|
||||||
"difficulty": "0x1",
|
"difficulty": "0x1",
|
||||||
|
|
|
||||||
|
|
@ -53,9 +53,8 @@ const (
|
||||||
defaultGasPrice = 50 * params.Shannon
|
defaultGasPrice = 50 * params.Shannon
|
||||||
// statuses of candidates
|
// statuses of candidates
|
||||||
statusMasternode = "MASTERNODE"
|
statusMasternode = "MASTERNODE"
|
||||||
statusSlashed = "SLASHED"
|
statusSlashed = "SLASHED"
|
||||||
statusProposed = "PROPOSED"
|
statusProposed = "PROPOSED"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// PublicEthereumAPI provides an API to access Ethereum related information.
|
// PublicEthereumAPI provides an API to access Ethereum related information.
|
||||||
|
|
@ -748,7 +747,7 @@ func (s *PublicBlockChainAPI) GetCandidateStatus(ctx context.Context, coinbaseAd
|
||||||
opts := new(bind.CallOpts)
|
opts := new(bind.CallOpts)
|
||||||
var (
|
var (
|
||||||
candidateAddresses []common.Address
|
candidateAddresses []common.Address
|
||||||
candidates []XDPoS.Masternode
|
candidates []XDPoS.Masternode
|
||||||
)
|
)
|
||||||
|
|
||||||
candidateAddresses, err = validator.GetCandidates(opts)
|
candidateAddresses, err = validator.GetCandidates(opts)
|
||||||
|
|
@ -779,13 +778,13 @@ func (s *PublicBlockChainAPI) GetCandidateStatus(ctx context.Context, coinbaseAd
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !isTopCandidate {
|
if isTopCandidate == false {
|
||||||
return status, nil
|
return status, nil
|
||||||
}
|
}
|
||||||
// look up recent checkpoint headers to get penalty list
|
// look up recent checkpoint headers to get penalty list
|
||||||
for i := 0; i <= common.LimitPenaltyEpoch; i++ {
|
for i := 0; i <= common.LimitPenaltyEpoch; i++ {
|
||||||
if blockNum > uint64(i)*epoch {
|
if blockNum > uint64(i)*epoch {
|
||||||
blockCheckpointNumber := rpc.BlockNumber(blockNum - (blockNum % epoch) - (uint64(i) * epoch))
|
blockCheckpointNumber := rpc.BlockNumber(blockNum - (blockNum % epoch) - (uint64(i) * epoch))
|
||||||
blockCheckpoint, err := s.b.BlockByNumber(ctx, blockCheckpointNumber)
|
blockCheckpoint, err := s.b.BlockByNumber(ctx, blockCheckpointNumber)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to get block by number", "num", blockCheckpointNumber, "err", err)
|
log.Error("Failed to get block by number", "num", blockCheckpointNumber, "err", err)
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ const (
|
||||||
// timeout waiting for M1
|
// timeout waiting for M1
|
||||||
waitPeriod = 10
|
waitPeriod = 10
|
||||||
// timeout for checkpoint.
|
// timeout for checkpoint.
|
||||||
waitPeriodCheckpoint = 120 // 2 mins
|
waitPeriodCheckpoint = 20
|
||||||
)
|
)
|
||||||
|
|
||||||
// Agent can register themself with the worker
|
// Agent can register themself with the worker
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ var (
|
||||||
//
|
//
|
||||||
// This configuration is intentionally not using keyed fields to force anyone
|
// This configuration is intentionally not using keyed fields to force anyone
|
||||||
// adding flags to the config to also have to set these fields.
|
// adding flags to the config to also have to set these fields.
|
||||||
AllXDPoSProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, &XDPoSConfig{Period: 0, Epoch: 30000}}
|
AllXDPoSProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, &XDPoSConfig{Period: 0, Epoch: 30000}}
|
||||||
AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}, nil}
|
AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}, nil}
|
||||||
TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil, nil}
|
TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil, nil}
|
||||||
TestRules = TestChainConfig.Rules(new(big.Int))
|
TestRules = TestChainConfig.Rules(new(big.Int))
|
||||||
|
|
@ -121,7 +121,7 @@ type ChainConfig struct {
|
||||||
// Various consensus engines
|
// Various consensus engines
|
||||||
Ethash *EthashConfig `json:"ethash,omitempty"`
|
Ethash *EthashConfig `json:"ethash,omitempty"`
|
||||||
Clique *CliqueConfig `json:"clique,omitempty"`
|
Clique *CliqueConfig `json:"clique,omitempty"`
|
||||||
XDPoS *XDPoSConfig `json:"XDPoS,omitempty"`
|
XDPoS *XDPoSConfig `json:"XDPoS,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// EthashConfig is the consensus engine configs for proof-of-work based sealing.
|
// EthashConfig is the consensus engine configs for proof-of-work based sealing.
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VersionMajor = 0 // Major version component of the current release
|
VersionMajor = 0 // Major version component of the current release
|
||||||
VersionMinor = 5 // Minor version component of the current release
|
VersionMinor = 5 // Minor version component of the current release
|
||||||
VersionPatch = 0 // Patch version component of the current release
|
VersionPatch = 0 // Patch version component of the current release
|
||||||
VersionMeta = "stable" // Version metadata to append to the version string
|
VersionMeta = "stable" // Version metadata to append to the version string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -190,14 +190,14 @@ func (s *Server) serveRequest(codec ServerCodec, singleShot bool, options CodecO
|
||||||
if singleShot {
|
if singleShot {
|
||||||
if batch {
|
if batch {
|
||||||
for _, req := range reqs {
|
for _, req := range reqs {
|
||||||
if req.callb != nil && req.callb.method.Name == "EnabledRPCSendTransaction" {
|
if req.callb != nil && req.callb.method.Name == "SendTransaction" {
|
||||||
codec.Write(codec.CreateErrorResponse(&req.id, &invalidRequestError{message: "Only support send transaction with ipc"}))
|
codec.Write(codec.CreateErrorResponse(&req.id, &invalidRequestError{message: "Only support send transaction with ipc"}))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s.execBatch(ctx, codec, reqs)
|
s.execBatch(ctx, codec, reqs)
|
||||||
} else {
|
} else {
|
||||||
if reqs[0].callb != nil && reqs[0].callb.method.Name == "EnabledRPCSendTransaction" {
|
if reqs[0].callb != nil && reqs[0].callb.method.Name == "SendTransaction" {
|
||||||
codec.Write(codec.CreateErrorResponse(&reqs[0].id, &invalidRequestError{message: "Only support send transaction with ipc"}))
|
codec.Write(codec.CreateErrorResponse(&reqs[0].id, &invalidRequestError{message: "Only support send transaction with ipc"}))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
vendor/github.com/btcsuite/btcd/btcec/secp256k1.go
generated
vendored
2
vendor/github.com/btcsuite/btcd/btcec/secp256k1.go
generated
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue