Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: some ethereum signature are not deleted #231

Open
wants to merge 1 commit into
base: v2.0.0-cronos
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion module/x/gravity/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func eventVoteRecordPruneAndTally(ctx sdk.Context, k keeper.Keeper) {
// This order is not important.
for _, att := range attmap[nonce] {
// delete all before the last nonce
if nonce < lastNonce {
if nonce <= lastNonce {
k.DeleteEthereumEventVoteRecord(ctx, att)
}
// We check if the event nonce is exactly 1 higher than the last attestation that was
Expand Down Expand Up @@ -318,6 +318,7 @@ func cleanupTimedOutContractCallTxs(ctx sdk.Context, k keeper.Keeper) {
k.IterateOutgoingTxsByType(ctx, types.ContractCallTxPrefixByte, func(_ []byte, otx types.OutgoingTx) bool {
cctx, _ := otx.(*types.ContractCallTx)
if cctx.Timeout < ethereumHeight {
k.DeleteEthereumSignatures(ctx, cctx)
k.DeleteOutgoingTx(ctx, cctx.GetStoreIndex())
}
return true
Expand Down
16 changes: 11 additions & 5 deletions module/x/gravity/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,18 +274,24 @@ func TestMsgSubmitEthreumEventSendToCosmosMultiValidator(t *testing.T) {
balance2 := input.BankKeeper.GetAllBalances(ctx, myCosmosAddr)
require.Equal(t, sdk.Coins{sdk.NewInt64Coin(denom, 12)}, balance2)

// and vouchers added to the account
// this happens when 2/3 of the voting power have submitted claims, so the third isn't required
balance3 := input.BankKeeper.GetAllBalances(ctx, myCosmosAddr)
require.Equal(t, sdk.Coins{sdk.NewInt64Coin(denom, 12)}, balance3)

// when
ctx = ctx.WithBlockTime(myBlockTime)
_, err = h(ctx, ethClaim3Msg)
gravity.EndBlocker(ctx, input.GravityKeeper)
require.NoError(t, err)

// and attestation persisted
// and attestations pruned
a1 = input.GravityKeeper.GetEthereumEventVoteRecord(ctx, myNonce, ethClaim1.Hash())
a2 = input.GravityKeeper.GetEthereumEventVoteRecord(ctx, myNonce, ethClaim2.Hash())
a3 := input.GravityKeeper.GetEthereumEventVoteRecord(ctx, myNonce, ethClaim3.Hash())
require.NotNil(t, a3)
// and no additional added to the account
balance3 := input.BankKeeper.GetAllBalances(ctx, myCosmosAddr)
require.Equal(t, sdk.Coins{sdk.NewInt64Coin(denom, 12)}, balance3)
require.Nil(t, a1)
require.Nil(t, a2)
require.Nil(t, a3)
}

func TestMsgSetDelegateAddresses(t *testing.T) {
Expand Down
14 changes: 8 additions & 6 deletions module/x/gravity/keeper/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
)

// BuildBatchTx starts the following process chain:
// - find bridged denominator for given voucher type
// - determine if a an unexecuted batch is already waiting for this token type, if so confirm the new batch would
// have a higher total fees. If not exit withtout creating a batch
// - select available transactions from the outgoing transaction pool sorted by fee desc
// - persist an outgoing batch object with an incrementing ID = nonce
// - emit an event
// - find bridged denominator for given voucher type
// - determine if a an unexecuted batch is already waiting for this token type, if so confirm the new batch would
// have a higher total fees. If not exit withtout creating a batch
// - select available transactions from the outgoing transaction pool sorted by fee desc
// - persist an outgoing batch object with an incrementing ID = nonce
// - emit an event
func (k Keeper) BuildBatchTx(ctx sdk.Context, contractAddress common.Address, maxElements int) *types.BatchTx {
if maxElements == 0 {
return nil
Expand Down Expand Up @@ -102,6 +102,7 @@ func (k Keeper) batchTxExecuted(ctx sdk.Context, tokenContract common.Address, n
}
}

k.DeleteEthereumSignatures(ctx, batchTx)
k.DeleteOutgoingTx(ctx, batchTx.GetStoreIndex())
return nil
}
Expand Down Expand Up @@ -145,6 +146,7 @@ func (k Keeper) CancelBatchTx(ctx sdk.Context, batch *types.BatchTx) {
}

// Delete batch since it is finished
k.DeleteEthereumSignatures(ctx, batch)
k.DeleteOutgoingTx(ctx, batch.GetStoreIndex())

ctx.EventManager().EmitEvent(
Expand Down
2 changes: 2 additions & 0 deletions module/x/gravity/keeper/contract_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ func (k Keeper) contractCallExecuted(ctx sdk.Context, invalidationScope []byte,
cctx, _ := otx.(*types.ContractCallTx)
if (cctx.InvalidationNonce < completedCallTx.InvalidationNonce) &&
bytes.Equal(cctx.InvalidationScope, completedCallTx.InvalidationScope) {
k.DeleteEthereumSignatures(ctx, cctx)
k.DeleteOutgoingTx(ctx, cctx.GetStoreIndex())
}
return false
})

k.DeleteEthereumSignatures(ctx, completedCallTx)
k.DeleteOutgoingTx(ctx, completedCallTx.GetStoreIndex())
}
30 changes: 15 additions & 15 deletions module/x/gravity/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,19 @@ func (k Keeper) GetLastUnbondingBlockHeight(ctx sdk.Context) uint64 {
// ETHEREUM SIGNATURES //
///////////////////////////////

// getEthereumSignature returns a valset confirmation by a nonce and validator address
// getEthereumSignature returns an ethereum signature by a nonce and validator address
func (k Keeper) getEthereumSignature(ctx sdk.Context, storeIndex []byte, validator sdk.ValAddress) []byte {
return ctx.KVStore(k.storeKey).Get(types.MakeEthereumSignatureKey(storeIndex, validator))
}

// SetEthereumSignature sets a valset confirmation
// SetEthereumSignature sets an ethereum signature
func (k Keeper) SetEthereumSignature(ctx sdk.Context, sig types.EthereumTxConfirmation, val sdk.ValAddress) []byte {
key := types.MakeEthereumSignatureKey(sig.GetStoreIndex(), val)
ctx.KVStore(k.storeKey).Set(key, sig.GetSignature())
return key
}

// GetEthereumSignatures returns all etherum signatures for a given outgoing tx by store index
// GetEthereumSignatures returns all ethereum signatures for a given outgoing tx by store index
func (k Keeper) GetEthereumSignatures(ctx sdk.Context, storeIndex []byte) map[string][]byte {
var signatures = make(map[string][]byte)
k.iterateEthereumSignatures(ctx, storeIndex, func(val sdk.ValAddress, h []byte) bool {
Expand All @@ -152,7 +152,18 @@ func (k Keeper) GetEthereumSignatures(ctx sdk.Context, storeIndex []byte) map[st
return signatures
}

// iterateEthereumSignatures iterates through all valset confirms by nonce in ASC order
// DeleteEthereumSignatures deletes the ethereum signatures for a specific outgoing tx
func (k Keeper) DeleteEthereumSignatures(ctx sdk.Context, otx types.OutgoingTx) {
prefixStoreSig := prefix.NewStore(ctx.KVStore(k.storeKey), append([]byte{types.EthereumSignatureKey}, otx.GetStoreIndex()...))
iterSig := prefixStoreSig.Iterator(nil, nil)
defer iterSig.Close()

for ; iterSig.Valid(); iterSig.Next() {
prefixStoreSig.Delete(iterSig.Key())
}
}

// iterateEthereumSignatures iterates through all ethereum signatures confirms by nonce in ASC order
func (k Keeper) iterateEthereumSignatures(ctx sdk.Context, storeIndex []byte, cb func(sdk.ValAddress, []byte) bool) {
prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), append([]byte{types.EthereumSignatureKey}, storeIndex...))
iter := prefixStore.Iterator(nil, nil)
Expand Down Expand Up @@ -643,17 +654,6 @@ func (k Keeper) IterateEthereumHeightVotes(ctx sdk.Context, cb func(val sdk.ValA
}
}

// DeleteEthereumSignatures deletes the ethereum signatures for a specific outgoing tx
func (k Keeper) DeleteEthereumSignatures(ctx sdk.Context, otx types.OutgoingTx) {
prefixStoreSig := prefix.NewStore(ctx.KVStore(k.storeKey), append([]byte{types.EthereumSignatureKey}, otx.GetStoreIndex()...))
iterSig := prefixStoreSig.Iterator(nil, nil)
defer iterSig.Close()

for ; iterSig.Valid(); iterSig.Next() {
prefixStoreSig.Delete(iterSig.Key())
}
}

/////////////////
// MIGRATE //
/////////////////
Expand Down