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

[Rewards] Fixed collectRewardsTx cross-chain request/response handling #110

Merged
merged 1 commit into from
Aug 7, 2024
Merged
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
23 changes: 0 additions & 23 deletions peer/camino_network.go

This file was deleted.

3 changes: 0 additions & 3 deletions peer/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ type Network interface {
// SendAppRequest sends message to given nodeID, notifying handler when there's a response or timeout
SendAppRequest(nodeID ids.NodeID, message []byte, handler message.ResponseHandler) error

// RequestCrossChain sends message to a given chainID, notifying handler when there's a response or timeout
RequestCrossChain(chainID ids.ID, message []byte, handler message.ResponseHandler) error

// Gossip sends given gossip message to peers
Gossip(gossip []byte) error

Expand Down
25 changes: 22 additions & 3 deletions plugin/evm/camino_collect_rewards_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
gconstants "github.com/ava-labs/coreth/constants"
"github.com/ava-labs/coreth/core/state"
"github.com/ava-labs/coreth/params"
evmMsg "github.com/ava-labs/coreth/plugin/evm/message"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
)
Expand All @@ -28,8 +29,9 @@ const (
)

var (
_ UnsignedAtomicTx = &UnsignedCollectRewardsTx{}
_ secp256k1fx.UnsignedTx = &UnsignedCollectRewardsTx{}
_ UnsignedAtomicTx = (*UnsignedCollectRewardsTx)(nil)
_ secp256k1fx.UnsignedTx = (*UnsignedCollectRewardsTx)(nil)
_ evmMsg.ResponseHandler = (*RewardsCrossChainMsgHandler)(nil)

FeeRewardAddress = common.HexToAddress(FeeRewardAddressStr)
FeeRewardAddressID, _ = ids.ToShortID(FeeRewardAddress.Bytes())
Expand Down Expand Up @@ -303,7 +305,11 @@ func (vm *VM) TriggerRewardsTx(block *Block) {
if err != nil {
log.Warn("cannot marshall reward message", "error", err)
}
vm.RequestCrossChain(ids.ID{}, request, nil)
vm.SendCrossChainRequest(
constants.PlatformChainID,
request,
&RewardsCrossChainMsgHandler{},
)
break
}
}
Expand Down Expand Up @@ -448,3 +454,16 @@ func feeRewardExportMinTimeInterval(vm *VM) uint64 {
}
return vm.ethConfig.Genesis.FeeRewardExportMinTimeInterval
}

type RewardsCrossChainMsgHandler struct {
}

func (h *RewardsCrossChainMsgHandler) OnResponse(response []byte) error {
log.Info("CollectRewards cross-chain request success", "response", string(response))
return nil
}

func (h *RewardsCrossChainMsgHandler) OnFailure() error {
log.Error("CollectRewards cross-chain request failed")
return nil
}