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

fix: staking related fixes #524

Merged
merged 1 commit into from
Jan 23, 2021
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
33 changes: 18 additions & 15 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,6 @@ import (
tmos "github.com/tendermint/tendermint/libs/os"
dbm "github.com/tendermint/tm-db"

"github.com/maticnetwork/heimdall/helper"
"github.com/maticnetwork/heimdall/x/chainmanager"
chainKeeper "github.com/maticnetwork/heimdall/x/chainmanager/keeper"
chainmanagerTypes "github.com/maticnetwork/heimdall/x/chainmanager/types"

"github.com/maticnetwork/heimdall/x/clerk"
clerkkeeper "github.com/maticnetwork/heimdall/x/clerk/keeper"
clerktypes "github.com/maticnetwork/heimdall/x/clerk/types"

// unnamed import of statik for swagger UI support
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"

Expand All @@ -58,9 +49,19 @@ import (
// slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"

hmparams "github.com/maticnetwork/heimdall/app/params"
"github.com/maticnetwork/heimdall/helper"
hmtypes "github.com/maticnetwork/heimdall/types"
"github.com/maticnetwork/heimdall/types/common"
hmmodule "github.com/maticnetwork/heimdall/types/module"
"github.com/maticnetwork/heimdall/x/chainmanager"
chainKeeper "github.com/maticnetwork/heimdall/x/chainmanager/keeper"
chainmanagerTypes "github.com/maticnetwork/heimdall/x/chainmanager/types"
"github.com/maticnetwork/heimdall/x/checkpoint"
checkpointkeeper "github.com/maticnetwork/heimdall/x/checkpoint/keeper"
checkpointtypes "github.com/maticnetwork/heimdall/x/checkpoint/types"
"github.com/maticnetwork/heimdall/x/clerk"
clerkkeeper "github.com/maticnetwork/heimdall/x/clerk/keeper"
clerktypes "github.com/maticnetwork/heimdall/x/clerk/types"
"github.com/maticnetwork/heimdall/x/gov"
govkeeper "github.com/maticnetwork/heimdall/x/gov/keeper"
govtypes "github.com/maticnetwork/heimdall/x/gov/types"
Expand All @@ -74,10 +75,6 @@ import (
topupkeeper "github.com/maticnetwork/heimdall/x/topup/keeper"
topuptypes "github.com/maticnetwork/heimdall/x/topup/types"

"github.com/maticnetwork/heimdall/x/checkpoint"
checkpointkeeper "github.com/maticnetwork/heimdall/x/checkpoint/keeper"
checkpointtypes "github.com/maticnetwork/heimdall/x/checkpoint/types"

// unnamed import of statik for swagger UI support
_ "github.com/maticnetwork/heimdall/client/docs/statik"
)
Expand Down Expand Up @@ -223,6 +220,12 @@ func NewHeimdallApp(
txDecoder: txDecoder,
}

//
// module communicator
//

moduleCommunicator := ModuleCommunicator{App: app}

//
// Keepers
//
Expand Down Expand Up @@ -267,15 +270,15 @@ func NewHeimdallApp(
app.GetSubspace(stakingtypes.ModuleName),
app.ChainKeeper,
app.BankKeeper,
nil,
moduleCommunicator,
)
app.CheckpointKeeper = checkpointkeeper.NewKeeper(
appCodec,
keys[checkpointtypes.StoreKey], // target store
app.GetSubspace(checkpointtypes.ModuleName),
app.StakingKeeper,
app.ChainKeeper,
nil,
moduleCommunicator,
)

app.GovKeeper = govkeeper.NewKeeper(
Expand Down
37 changes: 37 additions & 0 deletions app/communicator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package app

import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/maticnetwork/heimdall/types"
)

// ModuleCommunicator retriever
type ModuleCommunicator struct {
App *HeimdallApp
}

// GetACKCount returns ack count
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from ethereum chain?

func (d ModuleCommunicator) GetACKCount(ctx sdk.Context) uint64 {
return d.App.CheckpointKeeper.GetACKCount(ctx)
}

// IsCurrentValidatorByAddress check if validator is current validator
func (d ModuleCommunicator) IsCurrentValidatorByAddress(ctx sdk.Context, address []byte) bool {
return d.App.StakingKeeper.IsCurrentValidatorByAddress(ctx, address)
}

// GetAllDividendAccounts fetches all dividend accounts from topup module
func (d ModuleCommunicator) GetAllDividendAccounts(ctx sdk.Context) []*types.DividendAccount {
return d.App.TopupKeeper.GetAllDividendAccounts(ctx)
}

// GetValidatorFromValID get validator from validator id
func (d ModuleCommunicator) GetValidatorFromValID(ctx sdk.Context, valID types.ValidatorID) (validator types.Validator, ok bool) {
return d.App.StakingKeeper.GetValidatorFromValID(ctx, valID)
}

// CreateValiatorSigningInfo creates ValidatorSigningInfo used by slashing module
func (d ModuleCommunicator) CreateValiatorSigningInfo(ctx sdk.Context, valID types.ValidatorID, valSigningInfo types.ValidatorSigningInfo) {
return
}
1 change: 1 addition & 0 deletions app/side_tx_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func (app *HeimdallApp) BeginSideBlocker(ctx sdk.Context, req abci.RequestBeginS
"yesVotes", signedPower[tmprototypes.SideTxResultType_YES],
"noVotes", signedPower[tmprototypes.SideTxResultType_NO],
"skipVotes", signedPower[tmprototypes.SideTxResultType_SKIP],
"err", rerr,
)
} else {
// add events
Expand Down
2 changes: 1 addition & 1 deletion types/dividend-account.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func UnMarshallDividendAccount(cdc codec.BinaryMarshaler, value []byte) (Dividen
}

// SortDividendAccountByAddress - Sorts DividendAccounts By Address
func SortDividendAccountByAddress(dividendAccounts []DividendAccount) []DividendAccount {
func SortDividendAccountByAddress(dividendAccounts []*DividendAccount) []*DividendAccount {
sort.Slice(dividendAccounts, func(i, j int) bool {
return dividendAccounts[i].User == dividendAccounts[j].User
})
Expand Down
2 changes: 1 addition & 1 deletion x/checkpoint/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var (

// ModuleCommunicator manages different module interaction
type ModuleCommunicator interface {
GetAllDividendAccounts(ctx sdk.Context) []hmTypes.DividendAccount
GetAllDividendAccounts(ctx sdk.Context) []*hmTypes.DividendAccount
}

type (
Expand Down
10 changes: 5 additions & 5 deletions x/checkpoint/types/merkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func ValidateCheckpoint(start uint64, end uint64, rootHash hmCommonTypes.Heimdal
}

// GetAccountRootHash returns roothash of Validator Account State Tree
func GetAccountRootHash(dividendAccounts []hmTypes.DividendAccount) ([]byte, error) {
func GetAccountRootHash(dividendAccounts []*hmTypes.DividendAccount) ([]byte, error) {
tree, err := GetAccountTree(dividendAccounts)
if err != nil {
return nil, err
Expand All @@ -48,7 +48,7 @@ func GetAccountRootHash(dividendAccounts []hmTypes.DividendAccount) ([]byte, err
}

// GetAccountTree returns roothash of Validator Account State Tree
func GetAccountTree(dividendAccounts []hmTypes.DividendAccount) (*merkletree.MerkleTree, error) {
func GetAccountTree(dividendAccounts []*hmTypes.DividendAccount) (*merkletree.MerkleTree, error) {
// Sort the dividendAccounts by ID
dividendAccounts = hmTypes.SortDividendAccountByAddress(dividendAccounts)
var list []merkletree.Content
Expand All @@ -66,11 +66,11 @@ func GetAccountTree(dividendAccounts []hmTypes.DividendAccount) (*merkletree.Mer
}

// GetAccountProof returns proof of dividend Account
func GetAccountProof(dividendAccounts []hmTypes.DividendAccount, userAddr sdk.AccAddress) ([]byte, uint64, error) {
func GetAccountProof(dividendAccounts []*hmTypes.DividendAccount, userAddr sdk.AccAddress) ([]byte, uint64, error) {
// Sort the dividendAccounts by user address
dividendAccounts = hmTypes.SortDividendAccountByAddress(dividendAccounts)
var list []merkletree.Content
var account hmTypes.DividendAccount
var account *hmTypes.DividendAccount
index := uint64(0)
for i := 0; i < len(dividendAccounts); i++ {
list = append(list, dividendAccounts[i])
Expand All @@ -93,7 +93,7 @@ func GetAccountProof(dividendAccounts []hmTypes.DividendAccount, userAddr sdk.Ac
}

// VerifyAccountProof returns proof of dividend Account
func VerifyAccountProof(dividendAccounts []hmTypes.DividendAccount, userAddr sdk.AccAddress, proofToVerify string) (bool, error) {
func VerifyAccountProof(dividendAccounts []*hmTypes.DividendAccount, userAddr sdk.AccAddress, proofToVerify string) (bool, error) {
proof, _, err := GetAccountProof(dividendAccounts, userAddr)
if err != nil {
return false, nil
Expand Down
Loading