charts, common, genesis, k8s: Fix bugs about ether sending
This commit is contained in:
parent
a51e1a5397
commit
0afa3f3bd7
|
@ -18,6 +18,7 @@ package charts
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
@ -51,6 +52,7 @@ func NewGenesisChart(addrs []common.Address, gasLimit uint64) *GenesisChart {
|
|||
false,
|
||||
genesis.Validators(addrs...),
|
||||
genesis.GasLimit(gasLimit),
|
||||
genesis.Alloc(addrs, new(big.Int).Exp(big.NewInt(10), big.NewInt(50), nil)),
|
||||
),
|
||||
}
|
||||
|
||||
|
|
|
@ -27,15 +27,20 @@ import (
|
|||
"github.com/getamis/istanbul-tools/client"
|
||||
)
|
||||
|
||||
var (
|
||||
DefaultGasPrice int64 = 20000000000
|
||||
DefaultGasLimit int64 = 22000 // the gas of ether tx should be 21000
|
||||
)
|
||||
|
||||
func SendEther(client *client.Client, from *ecdsa.PrivateKey, to common.Address, amount *big.Int, nonce uint64) error {
|
||||
tx := types.NewTransaction(nonce, to, amount, nil, nil, []byte{})
|
||||
signedTx, err := types.SignTx(tx, types.EIP155Signer{}, from)
|
||||
tx := types.NewTransaction(nonce, to, amount, big.NewInt(DefaultGasLimit), big.NewInt(DefaultGasPrice), []byte{})
|
||||
signedTx, err := types.SignTx(tx, types.NewEIP155Signer(big.NewInt(2017)), from)
|
||||
if err != nil {
|
||||
log.Error("Failed to sign transaction", "tx", tx, "err", err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = client.SendRawTransaction(context.Background(), tx)
|
||||
err = client.SendRawTransaction(context.Background(), signedTx)
|
||||
if err != nil {
|
||||
log.Error("Failed to send transaction", "tx", signedTx, "nonce", nonce, "err", err)
|
||||
return err
|
||||
|
|
|
@ -46,6 +46,7 @@ func New(options ...Option) *core.Genesis {
|
|||
Difficulty: big.NewInt(InitDifficulty),
|
||||
Alloc: make(core.GenesisAlloc),
|
||||
Config: ¶ms.ChainConfig{
|
||||
ChainId: big.NewInt(2017),
|
||||
HomesteadBlock: big.NewInt(1),
|
||||
EIP150Block: big.NewInt(2),
|
||||
EIP155Block: big.NewInt(3),
|
||||
|
|
|
@ -94,10 +94,6 @@ func (bc *blockchain) Stop(force bool) error {
|
|||
}
|
||||
|
||||
func (bc *blockchain) Finalize() {
|
||||
for _, v := range bc.validators {
|
||||
v.Stop()
|
||||
}
|
||||
|
||||
bc.staticNodes.Uninstall()
|
||||
bc.genesis.Uninstall()
|
||||
}
|
||||
|
@ -121,7 +117,9 @@ func (bc *blockchain) setupValidators(num int, nodekeys []string, ips []string,
|
|||
opts...,
|
||||
)
|
||||
|
||||
bc.validators = append(bc.validators, geth)
|
||||
if geth != nil {
|
||||
bc.validators = append(bc.validators, geth)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"crypto/ecdsa"
|
||||
"errors"
|
||||
"math/big"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -106,11 +107,18 @@ func (eth *ethereum) DockerBinds() []string {
|
|||
}
|
||||
|
||||
func (eth *ethereum) NewClient() *client.Client {
|
||||
client, err := client.Dial("ws://" + eth.Host() + ":8546")
|
||||
if err != nil {
|
||||
return nil
|
||||
for i := 0; i < healthCheckRetryCount; i++ {
|
||||
client, err := client.Dial("ws://" + eth.Host() + ":8546")
|
||||
if err != nil {
|
||||
log.Warn("Failed to create client", "err", err)
|
||||
<-time.After(healthCheckRetryDelay)
|
||||
continue
|
||||
} else {
|
||||
return client
|
||||
}
|
||||
}
|
||||
return client
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (eth *ethereum) NodeAddress() string {
|
||||
|
@ -350,9 +358,16 @@ func (eth *ethereum) Accounts() []accounts.Account {
|
|||
// ----------------------------------------------------------------------------
|
||||
|
||||
func (eth *ethereum) Host() string {
|
||||
svc, err := eth.k8sClient.CoreV1().Services(defaultNamespace).Get(eth.chart.Name()+"-0", metav1.GetOptions{})
|
||||
if err != nil {
|
||||
index := strings.LastIndex(eth.chart.Name(), "-")
|
||||
if index < 0 {
|
||||
log.Error("Invalid validator pod name")
|
||||
return ""
|
||||
}
|
||||
return svc.Spec.LoadBalancerIP
|
||||
name := "validator-service-" + eth.chart.Name()[index+1:]
|
||||
svc, err := eth.k8sClient.CoreV1().Services(defaultNamespace).Get(name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
log.Error("Failed to find service", "svc", name, "err", err)
|
||||
return ""
|
||||
}
|
||||
return svc.Status.LoadBalancer.Ingress[0].IP
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue