Skip to content

Commit

Permalink
Merge pull request #524 from maticnetwork/jdkanani/staking-fix-1
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkanani authored Jan 23, 2021
2 parents 880c2fb + f1a678d commit ce36ea8
Show file tree
Hide file tree
Showing 8 changed files with 251 additions and 194 deletions.
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
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

0 comments on commit ce36ea8

Please sign in to comment.