Skip to content

Commit

Permalink
resolve conflict from sidechannel branch
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkanani committed Apr 30, 2020
2 parents 9641022 + 85545cc commit 838c0ed
Show file tree
Hide file tree
Showing 74 changed files with 594 additions and 387 deletions.
35 changes: 0 additions & 35 deletions .circleci/config.yml

This file was deleted.

14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: CI

on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: 1.13
- name: "Build binaries"
run: make build
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ldflags = -X github.com/maticnetwork/heimdall/version.Name=heimdall \
-X github.com/maticnetwork/heimdall/version.ClientName=heimdallcli \
-X github.com/maticnetwork/heimdall/version.Version=$(VERSION) \
-X github.com/maticnetwork/heimdall/version.Commit=$(COMMIT) \
-X github.com/cosmos/cosmos-sdk/version.Name=heimdall \
-X github.com/cosmos/cosmos-sdk/version.Name=heimdall \
-X github.com/cosmos/cosmos-sdk/version.ServerName=heimdalld \
-X github.com/cosmos/cosmos-sdk/version.ClientName=heimdallcli \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
Expand Down
4 changes: 3 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,9 @@ func (app *HeimdallApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) ab
amount := moduleAccount.GetCoins().AmountOf(authTypes.FeeToken)
if !amount.IsZero() {
coins := sdk.Coins{sdk.Coin{Denom: authTypes.FeeToken, Amount: amount}}
app.SupplyKeeper.SendCoinsFromModuleToAccount(ctx, authTypes.FeeCollectorName, proposer, coins)
if err := app.SupplyKeeper.SendCoinsFromModuleToAccount(ctx, authTypes.FeeCollectorName, proposer, coins); err != nil {
logger.Error("EndBlocker | SendCoinsFromModuleToAccount", "Error", err)
}
}

// remove block proposer
Expand Down
2 changes: 0 additions & 2 deletions auth/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ import (
var (
// simulation signature values used to estimate gas consumption
simSecp256k1Pubkey secp256k1.PubKeySecp256k1
simSecp256k1Sig [64]byte

// fee wanted for checkpoint transaction
gasWantedPerCheckpoinTx sdk.Gas = 10000000
gasUsedPerCheckpointTx sdk.Gas = gasWantedPerCheckpoinTx - 1000000

// DefaultFeeInMatic represents default fee in matic
DefaultFeeInMatic = big.NewInt(10).Exp(big.NewInt(10), big.NewInt(15), nil)
Expand Down
10 changes: 4 additions & 6 deletions auth/client/cli/flags.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package cli

const (
flagMultisig = "multisig"
flagAppend = "append"
flagValidateSigs = "validate-signatures"
flagOffline = "offline"
flagSigOnly = "signature-only"
flagOutfile = "output-document"
flagAppend = "append"
flagOffline = "offline"
flagSigOnly = "signature-only"
flagOutfile = "output-document"
)
4 changes: 3 additions & 1 deletion auth/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ $ %s query auth params
}

var params types.Params
json.Unmarshal(bz, &params)
if err := json.Unmarshal(bz, &params); err != nil {
return err
}
return cliCtx.PrintOutput(params)
},
}
Expand Down
99 changes: 8 additions & 91 deletions auth/client/cli/tx_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ package cli
import (
"fmt"
"os"
"strings"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/spf13/cobra"
"github.com/spf13/viper"
amino "github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/crypto/multisig"

"github.com/maticnetwork/heimdall/auth/types"
"github.com/maticnetwork/heimdall/helper"
hmTypes "github.com/maticnetwork/heimdall/types"
)

var logger = helper.Logger.With("module", "auth/client/cli")

// GetSignCommand returns the transaction sign command.
func GetSignCommand(codec *amino.Codec) *cobra.Command {
cmd := &cobra.Command{
Expand Down Expand Up @@ -60,8 +57,12 @@ func preSignCmd(cmd *cobra.Command, _ []string) {
// Conditionally mark the account and sequence numbers required as no RPC
// query will be done.
if viper.GetBool(flagOffline) {
cmd.MarkFlagRequired(client.FlagAccountNumber)
cmd.MarkFlagRequired(client.FlagSequence)
if err := cmd.MarkFlagRequired(client.FlagAccountNumber); err != nil {
logger.Error("preSignCmd | MarkFlagRequired | FlagAccountNumber", "Error", err)
}
if err := cmd.MarkFlagRequired(client.FlagSequence); err != nil {
logger.Error("preSignCmd | MarkFlagRequired | FlagSequence", "Error", err)
}
}
}

Expand Down Expand Up @@ -130,87 +131,3 @@ func makeSignCmd(cdc *amino.Codec) func(cmd *cobra.Command, args []string) error
return
}
}

// printAndValidateSigs will validate the signatures of a given transaction over
// its expected signers. In addition, if offline has not been supplied, the
// signature is verified over the transaction sign bytes.
func printAndValidateSigs(
cliCtx context.CLIContext, chainID string, stdTx auth.StdTx, offline bool,
) bool {

fmt.Println("Signers:")

signers := stdTx.GetSigners()
for i, signer := range signers {
fmt.Printf(" %v: %v\n", i, signer.String())
}

success := true
sigs := stdTx.GetSignatures()

fmt.Println("")
fmt.Println("Signatures:")

if len(sigs) != len(signers) {
success = false
}

for i, sig := range sigs {
sigAddr := hmTypes.BytesToHeimdallAddress(sig.Address().Bytes())
sigSanity := "OK"

var (
multiSigHeader string
multiSigMsg string
)

if i >= len(signers) || !sigAddr.Equals(signers[i]) {
sigSanity = "ERROR: signature does not match its respective signer"
success = false
}

// Validate the actual signature over the transaction bytes since we can
// reach out to a full node to query accounts.
if !offline && success {
acc, err := types.NewAccountRetriever(cliCtx).GetAccount(sigAddr)
if err != nil {
fmt.Printf("failed to get account: %s\n", sigAddr)
return false
}

sigBytes := auth.StdSignBytes(
chainID, acc.GetAccountNumber(), acc.GetSequence(),
stdTx.Fee, stdTx.GetMsgs(), stdTx.GetMemo(),
)

if ok := sig.VerifyBytes(sigBytes, sig.Signature); !ok {
sigSanity = "ERROR: signature invalid"
success = false
}
}

multiPK, ok := sig.PubKey.(multisig.PubKeyMultisigThreshold)
if ok {
var multiSig multisig.Multisignature
cliCtx.Codec.MustUnmarshalBinaryBare(sig.Signature, &multiSig)

var b strings.Builder
b.WriteString("\n MultiSig Signatures:\n")

for i := 0; i < multiSig.BitArray.Size(); i++ {
if multiSig.BitArray.GetIndex(i) {
addr := sdk.AccAddress(multiPK.PubKeys[i].Address().Bytes())
b.WriteString(fmt.Sprintf(" %d: %s (weight: %d)\n", i, addr, 1))
}
}

multiSigHeader = fmt.Sprintf(" [multisig threshold: %d/%d]", multiPK.K, len(multiPK.PubKeys))
multiSigMsg = b.String()
}

fmt.Printf(" %d: %s\t\t\t[%s]%s%s\n", i, sigAddr.String(), sigSanity, multiSigHeader, multiSigMsg)
}

fmt.Println("")
return success
}
13 changes: 0 additions & 13 deletions auth/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,6 @@ func validateSigVerifyCostSecp256k1(i interface{}) error {
return nil
}

func validateMaxMemoCharacters(i interface{}) error {
v, ok := i.(uint64)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v == 0 {
return fmt.Errorf("invalid max memo characters: %d", v)
}

return nil
}

func validateTxSizeCostPerByte(i interface{}) error {
v, ok := i.(uint64)
if !ok {
Expand Down
10 changes: 4 additions & 6 deletions auth/types/pulp.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,15 @@ func NewPulp() *Pulp {
}

// GetPulpHash returns string hash
func GetPulpHash(name string) []byte {
return crypto.Keccak256([]byte(name))[:PulpHashLength]
func GetPulpHash(msg sdk.Msg) []byte {
return crypto.Keccak256([]byte(fmt.Sprintf("%s::%s", msg.Route(), msg.Type())))[:PulpHashLength]
}

// RegisterConcrete should be used to register concrete types that will appear in
// interface fields/elements to be encoded/decoded by pulp.
func (p *Pulp) RegisterConcrete(msg sdk.Msg) {
rtype := reflect.TypeOf(msg)
name := fmt.Sprintf("%s::%s", msg.Route(), msg.Type())
p.typeInfos[hex.EncodeToString(GetPulpHash(name))] = rtype
p.typeInfos[hex.EncodeToString(GetPulpHash(msg))] = rtype
}

// GetMsgTxInstance get new instance associated with base tx
Expand All @@ -62,13 +61,12 @@ func (p *Pulp) GetMsgTxInstance(hash []byte) interface{} {
// EncodeToBytes encodes msg to bytes
func (p *Pulp) EncodeToBytes(tx StdTx) ([]byte, error) {
msg := tx.GetMsgs()[0]
name := fmt.Sprintf("%s::%s", msg.Route(), msg.Type())
txBytes, err := rlp.EncodeToBytes(tx)
if err != nil {
return nil, err
}

return append(GetPulpHash(name), txBytes[:]...), nil
return append(GetPulpHash(msg), txBytes[:]...), nil
}

// DecodeBytes decodes bytes to msg
Expand Down
20 changes: 20 additions & 0 deletions auth/types/pulp_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package types

import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
assert "github.com/stretchr/testify/require"
)

func TestGetPulpHash(t *testing.T) {
tc := struct {
in sdk.Msg
out []byte
}{
in: sdk.NewTestMsg(nil),
out: []byte{142, 88, 179, 79},
}
out := GetPulpHash(tc.in)
assert.Equal(t, string(tc.out), string(out))
}
2 changes: 0 additions & 2 deletions auth/types/stdtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (

var (
_ sdk.Tx = (*StdTx)(nil)

maxGasWanted = uint64((1 << 63) - 1)
)

// StdTx is a standard way to wrap a Msg with Fee and Signatures.
Expand Down
9 changes: 7 additions & 2 deletions bor/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ func GetSpan(cdc *codec.Codec) *cobra.Command {
}

cmd.Flags().Uint64(FlagSpanId, 0, "--id=<span ID here>")
cmd.MarkFlagRequired(FlagSpanId)
if err := cmd.MarkFlagRequired(FlagSpanId); err != nil {
cliLogger.Error("GetSpan | MarkFlagRequired | FlagSpanId", "Error", err)
}

return cmd
}
Expand Down Expand Up @@ -139,7 +141,10 @@ $ %s query bor params
}

var params types.Params
json.Unmarshal(bz, &params)
err = json.Unmarshal(bz, &params)
if err != nil {
return err
}
return cliCtx.PrintOutput(params)
},
}
Expand Down
10 changes: 8 additions & 2 deletions bor/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
hmTypes "github.com/maticnetwork/heimdall/types"
)

var cliLogger = helper.Logger.With("module", "bor/client/cli")

// GetTxCmd returns the transaction commands for this module
func GetTxCmd(cdc *codec.Codec) *cobra.Command {
txCmd := &cobra.Command{
Expand Down Expand Up @@ -113,8 +115,12 @@ func PostSendProposeSpanTx(cdc *codec.Codec) *cobra.Command {
cmd.Flags().String(FlagSpanId, "", "--span-id=<span-id>")
cmd.Flags().String(FlagBorChainId, "", "--bor-chain-id=<bor-chain-id>")
cmd.Flags().String(FlagStartBlock, "", "--start-block=<start-block-number>")
cmd.MarkFlagRequired(FlagBorChainId)
cmd.MarkFlagRequired(FlagStartBlock)
if err := cmd.MarkFlagRequired(FlagBorChainId); err != nil {
cliLogger.Error("PostSendProposeSpanTx | MarkFlagRequired | FlagBorChainId", "Error", err)
}
if err := cmd.MarkFlagRequired(FlagStartBlock); err != nil {
cliLogger.Error("PostSendProposeSpanTx | MarkFlagRequired | FlagStartBlock", "Error", err)
}

return cmd
}
4 changes: 3 additions & 1 deletion bor/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) {
hmTypes.SortSpanByID(data.Spans)
// add new span
for _, span := range data.Spans {
keeper.AddNewRawSpan(ctx, *span)
if err := keeper.AddNewRawSpan(ctx, *span); err != nil {
keeper.Logger(ctx).Error("Error AddNewRawSpan", "error", err)
}
}

// update last span
Expand Down
2 changes: 1 addition & 1 deletion bor/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func HandleMsgProposeSpan(ctx sdk.Context, msg types.MsgProposeSpan, k Keeper) s
}

// get last span
lastSpan, err = k.GetLastSpan(ctx)
_, err = k.GetLastSpan(ctx)
if err != nil {
k.Logger(ctx).Error("Unable to fetch last span", "Error", err)
return common.ErrSpanNotFound(k.Codespace()).Result()
Expand Down
Loading

0 comments on commit 838c0ed

Please sign in to comment.