Skip to content

Commit

Permalink
MAT-1397 - resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
mankenavenkatesh committed May 14, 2020
2 parents 3e838ef + c25745a commit 88118df
Show file tree
Hide file tree
Showing 58 changed files with 1,303 additions and 626 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ jobs:
go-version: 1.13
- name: "Build binaries"
run: make build
- name: "Run tests"
run: make tests
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ logs

.idea
.vscode

*.out
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ clean:
rm -rf build

tests:
go test -v ./...
# go test -v ./...
go test -v ./app/ ./auth/ ./clerk/ ./sidechannel/ ./bank/ ./chainmanager/


build: clean
mkdir -p build
Expand Down
3 changes: 2 additions & 1 deletion auth/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ func (suite *AnteTestSuite) TestSigErrors() {
tx1 := types.NewTestTx(ctx, msg1, priv1, uint64(0), uint64(0)) // use sdk's auth module for msg

// Check no signatures fails
checkInvalidTx(t, anteHandler, ctx, tx1, false, sdk.CodeNoSignatures)
require.Equal(t, 0, len(msg1.GetSigners()))
checkInvalidTx(t, anteHandler, ctx, tx1, false, sdk.CodeUnauthorized)

// unknown address error
msg2 := sdkAuth.NewTestMsg(addr1) // using first address
Expand Down
7 changes: 0 additions & 7 deletions bank/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,13 @@ package types

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

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

// RegisterCodec registers concrete types on codec codec
func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterConcrete(MsgSend{}, "bank/MsgSend", nil)
}

// RegisterPulp register pulp
func RegisterPulp(pulp *authTypes.Pulp) {
pulp.RegisterConcrete(MsgSend{})
}

// ModuleCdc module cdc
var ModuleCdc = codec.New()

Expand Down
6 changes: 0 additions & 6 deletions bor/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@ package types

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

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

func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterConcrete(MsgProposeSpan{}, "bor/MsgProposeSpan", nil)
}

func RegisterPulp(pulp *authTypes.Pulp) {
pulp.RegisterConcrete(MsgProposeSpan{})
}

// ModuleCdc generic sealed codec to be used throughout module
var ModuleCdc *codec.Codec

Expand Down
2 changes: 1 addition & 1 deletion bridge/setu/listener/rootchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (rl *RootChainListener) queryAndBroadcastEvents(rootchainContext *RootChain
if err := helper.UnpackLog(rl.stakingInfoAbi, event, selectedEvent.Name, &vLog); err != nil {
rl.Logger.Error("Error while parsing event", "name", selectedEvent.Name, "error", err)
}
if bytes.Equal(event.Signer.Bytes(), helper.GetAddress()) {
if bytes.Equal(event.User.Bytes(), helper.GetAddress()) {
rl.sendTaskWithDelay("sendTopUpFeeToHeimdall", selectedEvent.Name, logBytes, 0)
} else if isCurrentValidator, delay := util.CalculateTaskDelay(rl.cliCtx); isCurrentValidator {
rl.sendTaskWithDelay("sendTopUpFeeToHeimdall", selectedEvent.Name, logBytes, delay)
Expand Down
19 changes: 17 additions & 2 deletions bridge/setu/processor/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,23 @@ func (cp *CheckpointProcessor) sendCheckpointToHeimdall(headerBlockStr string) (
}
start := expectedCheckpointState.newStart
end := expectedCheckpointState.newEnd
// TODO - add a check to see if this checkpoint has to be proposed or not.
// Fetch latest checkpoint from buffer. if expectedCheckpointState.newStart == start, don't send checkpoint

//
// Check checkpoint buffer
//
timeStamp := uint64(time.Now().Unix())
checkpointBufferTime := uint64(checkpointContext.CheckpointParams.CheckpointBufferTime.Seconds())

bufferedCheckpoint, err := util.GetBufferedCheckpoint(cp.cliCtx)
if err != nil {
cp.Logger.Debug("No buffered checkpoint", "bufferedCheckpoint", bufferedCheckpoint)
}

if bufferedCheckpoint != nil && !(bufferedCheckpoint.TimeStamp == 0 || ((timeStamp > bufferedCheckpoint.TimeStamp) && timeStamp-bufferedCheckpoint.TimeStamp >= checkpointBufferTime)) {
cp.Logger.Info("Checkpoint already exits in buffer", "Checkpoint", bufferedCheckpoint.String())
return nil
}

if err := cp.createAndSendCheckpointToHeimdall(checkpointContext, start, end); err != nil {
cp.Logger.Error("Error sending checkpoint to heimdall", "error", err)
return err
Expand Down
8 changes: 3 additions & 5 deletions bridge/setu/processor/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ func (fp *FeeProcessor) sendTopUpFeeToHeimdall(eventName string, logBytes string
if isOld, _ := fp.isOldTx(fp.cliCtx, vLog.TxHash.String(), uint64(vLog.Index)); isOld {
fp.Logger.Info("Ignoring task to send topup to heimdall as already processed",
"event", eventName,
"validatorId", event.ValidatorId,
"Signer", event.Signer,
"user", event.User,
"Fee", event.Fee,
"txHash", hmTypes.BytesToHeimdallHash(vLog.TxHash.Bytes()),
"logIndex", uint64(vLog.Index),
Expand All @@ -70,16 +69,15 @@ func (fp *FeeProcessor) sendTopUpFeeToHeimdall(eventName string, logBytes string

fp.Logger.Info("✅ sending topup to heimdall",
"event", eventName,
"validatorId", event.ValidatorId,
"Signer", event.Signer,
"user", event.User,
"Fee", event.Fee,
"txHash", hmTypes.BytesToHeimdallHash(vLog.TxHash.Bytes()),
"logIndex", uint64(vLog.Index),
"blockNumber", vLog.BlockNumber,
)

// create msg checkpoint ack message
msg := topupTypes.NewMsgTopup(helper.GetFromAddress(fp.cliCtx), event.ValidatorId.Uint64(), hmTypes.BytesToHeimdallAddress(event.Signer.Bytes()), sdk.NewIntFromBigInt(event.Fee), hmTypes.BytesToHeimdallHash(vLog.TxHash.Bytes()), uint64(vLog.Index), vLog.BlockNumber)
msg := topupTypes.NewMsgTopup(helper.GetFromAddress(fp.cliCtx), hmTypes.BytesToHeimdallAddress(event.User.Bytes()), sdk.NewIntFromBigInt(event.Fee), hmTypes.BytesToHeimdallHash(vLog.TxHash.Bytes()), uint64(vLog.Index), vLog.BlockNumber)

// return broadcast to heimdall
if err := fp.txBroadcaster.BroadcastToHeimdall(msg); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions bridge/setu/processor/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func (sp *SpanProcessor) Start() error {
sp.cancelSpanService = cancelSpanService

// start polling for span
sp.Logger.Info("Start polling for span", "pollInterval", helper.GetConfig().SpanPollingInterval)
go sp.startPolling(spanCtx, helper.GetConfig().SpanPollingInterval)
sp.Logger.Info("Start polling for span", "pollInterval", helper.GetConfig().SpanPollInterval)
go sp.startPolling(spanCtx, helper.GetConfig().SpanPollInterval)
return nil
}

Expand Down
56 changes: 39 additions & 17 deletions bridge/setu/util/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,30 @@ import (
"sync"
"time"

mLog "github.com/RichardKnop/machinery/v1/log"
cliContext "github.com/cosmos/cosmos-sdk/client/context"
authTypes "github.com/maticnetwork/heimdall/auth/types"
chainManagerTypes "github.com/maticnetwork/heimdall/chainmanager/types"
checkpointTypes "github.com/maticnetwork/heimdall/checkpoint/types"

"github.com/maticnetwork/heimdall/types"

"github.com/pkg/errors"
"github.com/spf13/viper"
"github.com/tendermint/tendermint/libs/log"
httpClient "github.com/tendermint/tendermint/rpc/client"
tmTypes "github.com/tendermint/tendermint/types"

authTypes "github.com/maticnetwork/heimdall/auth/types"
chainManagerTypes "github.com/maticnetwork/heimdall/chainmanager/types"
checkpointTypes "github.com/maticnetwork/heimdall/checkpoint/types"
"github.com/maticnetwork/heimdall/helper"
"github.com/maticnetwork/heimdall/types"
hmtypes "github.com/maticnetwork/heimdall/types"
)

const (
ChainSyncer = "chain-syncer"
HeimdallCheckpointer = "heimdall-checkpointer"
NoackService = "checkpoint-no-ack"
SpanServiceStr = "span-service"
ClerkServiceStr = "clerk-service"
AMQPConsumerService = "amqp-consumer-service"

AccountDetailsURL = "/auth/accounts/%v"
LastNoAckURL = "/checkpoint/last-no-ack"
CheckpointParamsURL = "/checkpoint/params"
LastNoAckURL = "/checkpoints/last-no-ack"
CheckpointParamsURL = "/checkpoints/params"
ChainManagerParamsURL = "/chainmanager/params"
ProposersURL = "/staking/proposer/%v"
BufferedCheckpointURL = "/checkpoint/buffer"
LatestCheckpointURL = "/checkpoint/latest-checkpoint"
BufferedCheckpointURL = "/checkpoints/buffer"
LatestCheckpointURL = "/checkpoints/latest"
CurrentProposerURL = "/staking/current-proposer"
LatestSpanURL = "/bor/latest-span"
NextSpanInfoURL = "/bor/prepare-next-span"
Expand Down Expand Up @@ -75,6 +67,11 @@ func Logger() log.Logger {
logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout))
option, _ := log.AllowLevel(viper.GetString("log_level"))
logger = log.NewFilter(logger, option)

// set no-op logger if log level is not debug for machinery
if viper.GetString("log_level") != "debug" {
mLog.SetDebug(NoopLogger{})
}
})

return logger
Expand Down Expand Up @@ -298,11 +295,13 @@ func GetChainmanagerParams(cliCtx cliContext.CLIContext) (*chainManagerTypes.Par
)

if err != nil {
logger.Error("Error fetching chainmanager params", "err", err)
return nil, err
}

var params chainManagerTypes.Params
if err := json.Unmarshal(response.Result, &params); err != nil {
logger.Error("Error unmarshalling chainmanager params", "url", ChainManagerParamsURL, "err", err)
return nil, err
}

Expand All @@ -317,17 +316,40 @@ func GetCheckpointParams(cliCtx cliContext.CLIContext) (*checkpointTypes.Params,
)

if err != nil {
logger.Error("Error fetching Checkpoint params", "err", err)
return nil, err
}

var params checkpointTypes.Params
if err := json.Unmarshal(response.Result, &params); err != nil {
logger.Error("Error unmarshalling Checkpoint params", "url", CheckpointParamsURL)
return nil, err
}

return &params, nil
}

// GetBufferedCheckpoint return checkpoint from bueffer
func GetBufferedCheckpoint(cliCtx cliContext.CLIContext) (*hmtypes.CheckpointBlockHeader, error) {
response, err := helper.FetchFromAPI(
cliCtx,
helper.GetHeimdallServerEndpoint(BufferedCheckpointURL),
)

if err != nil {
logger.Debug("Error fetching buffered checkpoint", "err", err)
return nil, err
}

var blockHeader hmtypes.CheckpointBlockHeader
if err := json.Unmarshal(response.Result, &blockHeader); err != nil {
logger.Error("Error unmarshalling buffered checkpoint", "url", BufferedCheckpointURL, "err", err)
return nil, err
}

return &blockHeader, nil
}

// AppendPrefix returns publickey in uncompressed format
func AppendPrefix(signerPubKey []byte) []byte {
// append prefix - "0x04" as heimdall uses publickey in uncompressed format. Refer below link
Expand Down
14 changes: 14 additions & 0 deletions bridge/setu/util/machinery_logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package util

// NoopLogger no operational logger
type NoopLogger struct{}

func (NoopLogger) Print(...interface{}) {}
func (NoopLogger) Printf(string, ...interface{}) {}
func (NoopLogger) Println(...interface{}) {}
func (NoopLogger) Fatal(...interface{}) {}
func (NoopLogger) Fatalf(string, ...interface{}) {}
func (NoopLogger) Fatalln(...interface{}) {}
func (NoopLogger) Panic(...interface{}) {}
func (NoopLogger) Panicf(string, ...interface{}) {}
func (NoopLogger) Panicln(...interface{}) {}
Loading

0 comments on commit 88118df

Please sign in to comment.