cherry picks ethermint

This commit is contained in:
Federico Kunze 2021-05-05 15:10:21 +02:00
parent 374d249116
commit 77be0bc022
No known key found for this signature in database
GPG Key ID: 655F93A970080A30
6 changed files with 44 additions and 10 deletions

View File

@ -42,6 +42,29 @@ func InitConfig(cmd *cobra.Command) error {
return viper.BindPFlag(cli.OutputFlag, cmd.PersistentFlags().Lookup(cli.OutputFlag)) return viper.BindPFlag(cli.OutputFlag, cmd.PersistentFlags().Lookup(cli.OutputFlag))
} }
// GenerateChainID wraps a cobra command with a RunE function with base 10 integer chain-id random generation
// when a chain-id is not provided.
func GenerateChainID(baseCmd *cobra.Command) *cobra.Command {
// Copy base run command to be used after chain verification
baseRunE := baseCmd.RunE
// Function to replace command's RunE function
generateFn := func(cmd *cobra.Command, args []string) error {
chainID, _ := cmd.Flags().GetString(flags.FlagChainID)
if chainID != "" {
if err := cmd.Flags().Set(flags.FlagChainID, ethermint.GenerateRandomChainID()); err != nil {
return fmt.Errorf("could not set random chain-id: %w", err)
}
}
return baseRunE(cmd, args)
}
baseCmd.RunE = generateFn
return baseCmd
}
// ValidateChainID wraps a cobra command with a RunE function with base 10 integer chain-id verification. // ValidateChainID wraps a cobra command with a RunE function with base 10 integer chain-id verification.
func ValidateChainID(baseCmd *cobra.Command) *cobra.Command { func ValidateChainID(baseCmd *cobra.Command) *cobra.Command {
// Copy base run command to be used after chain verification // Copy base run command to be used after chain verification

View File

@ -26,10 +26,10 @@ func TestAddTopic(t *testing.T) {
func TestSubscribe(t *testing.T) { func TestSubscribe(t *testing.T) {
q := NewEventBus() q := NewEventBus()
kekSrc := make(<-chan coretypes.ResultEvent) kekSrc := make(chan coretypes.ResultEvent)
q.AddTopic("kek", kekSrc) q.AddTopic("kek", kekSrc)
lolSrc := make(<-chan coretypes.ResultEvent) lolSrc := make(chan coretypes.ResultEvent)
q.AddTopic("lol", lolSrc) q.AddTopic("lol", lolSrc)
kekSubC, err := q.Subscribe("kek") kekSubC, err := q.Subscribe("kek")
@ -69,8 +69,9 @@ func TestSubscribe(t *testing.T) {
defer wg.Done() defer wg.Done()
time.Sleep(time.Second) time.Sleep(time.Second)
<-kekSrc
<-lolSrc close(kekSrc)
close(lolSrc)
}() }()
wg.Wait() wg.Wait()

View File

@ -44,6 +44,8 @@ func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*t
txHash := tmtypes.Tx(ctx.TxBytes()).Hash() txHash := tmtypes.Tx(ctx.TxBytes()).Hash()
ethHash := ethcmn.BytesToHash(txHash) ethHash := ethcmn.BytesToHash(txHash)
blockHash, _ := k.GetBlockHashFromHeight(ctx, ctx.BlockHeight())
ethBlockHash := ethcmn.BytesToHash(blockHash)
var recipient *ethcmn.Address var recipient *ethcmn.Address
if len(msg.Data.Recipient) > 0 { if len(msg.Data.Recipient) > 0 {
@ -70,8 +72,7 @@ func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*t
// other nodes, causing a consensus error // other nodes, causing a consensus error
if !st.Simulate { if !st.Simulate {
// Prepare db for logs // Prepare db for logs
hash, _ := k.GetBlockHashFromHeight(ctx, ctx.BlockHeight()) k.Prepare(ctx, ethHash, ethBlockHash, k.TxCount)
k.Prepare(ctx, ethHash, ethcmn.BytesToHash(hash), k.TxCount)
k.TxCount++ k.TxCount++
} }
@ -87,7 +88,6 @@ func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*t
executionResult.Response.Reverted = true executionResult.Response.Reverted = true
if !st.Simulate { if !st.Simulate {
blockHash, _ := k.GetBlockHashFromHeight(ctx, ctx.BlockHeight())
k.SetTxReceiptToHash(ctx, ethHash, &types.TxReceipt{ k.SetTxReceiptToHash(ctx, ethHash, &types.TxReceipt{
Hash: ethHash.Bytes(), Hash: ethHash.Bytes(),
From: sender.Bytes(), From: sender.Bytes(),

View File

@ -126,3 +126,13 @@ func validateBlock(block sdk.Int) error {
return nil return nil
} }
// IsIstanbul returns whether the Istanbul version is enabled.
func (cc ChainConfig) IsIstanbul() bool {
return getBlockValue(cc.IstanbulBlock) != nil
}
// IsHomestead returns whether the Homestead version is enabled.
func (cc ChainConfig) IsHomestead() bool {
return getBlockValue(cc.HomesteadBlock) != nil
}

View File

@ -24,7 +24,7 @@ var big8 = big.NewInt(8)
// message type and route constants // message type and route constants
const ( const (
// TypeMsgEthereumTx defines the type string of an Ethereum tranasction // TypeMsgEthereumTx defines the type string of an Ethereum transaction
TypeMsgEthereumTx = "ethereum" TypeMsgEthereumTx = "ethereum"
) )

View File

@ -61,7 +61,7 @@ func GetHashFn(ctx sdk.Context, csdb *CommitStateDB) vm.GetHashFunc {
case ctx.BlockHeight() == int64(height): case ctx.BlockHeight() == int64(height):
// Case 1: The requested height matches the one from the context so we can retrieve the header // Case 1: The requested height matches the one from the context so we can retrieve the header
// hash directly from the context. // hash directly from the context.
return HashFromContext(ctx) return csdb.bhash
case ctx.BlockHeight() > int64(height): case ctx.BlockHeight() > int64(height):
// Case 2: if the chain is not the current height we need to retrieve the hash from the store for the // Case 2: if the chain is not the current height we need to retrieve the hash from the store for the
@ -190,7 +190,7 @@ func (st *StateTransition) TransitionDb(ctx sdk.Context, config ChainConfig) (re
ret, contractAddress, leftOverGas, err = evm.Create(senderRef, st.Payload, gasLimit, st.Amount) ret, contractAddress, leftOverGas, err = evm.Create(senderRef, st.Payload, gasLimit, st.Amount)
if err != nil { if err != nil {
log.WithField("simulate?", st.Simulate). log.WithField("simulate", st.Simulate).
WithField("AccountNonce", st.AccountNonce). WithField("AccountNonce", st.AccountNonce).
WithField("contract", contractAddress.String()). WithField("contract", contractAddress.String()).
WithError(err).Warningln("evm contract creation failed") WithError(err).Warningln("evm contract creation failed")