Skip to content

Commit

Permalink
Merge pull request #766 from HaoyangLiu/haoyang/develop
Browse files Browse the repository at this point in the history
R4R: Add unit tests for store and merge PRs
  • Loading branch information
HaoyangLiu authored Dec 5, 2018
2 parents 8d690e0 + b7ec95a commit 14bdb81
Show file tree
Hide file tree
Showing 25 changed files with 2,572 additions and 68 deletions.
28 changes: 19 additions & 9 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@

[[override]]
name = "github.com/tendermint/iavl"
version = "=v0.11.1"
# version = "=v0.11.1"
source = "https://github.com/irisnet/iavl.git"
branch = "irisnet/v0.12.0-iris"

[[override]]
name = "github.com/tendermint/tendermint"
source = "https://github.com/irisnet/tendermint.git"
version = "=v0.26.1-rc3-iris"

[[constraint]]
name = "github.com/prometheus/client_golang"
revision = "ae27198cdd90bf12cd134ad79d1366a6cf49f632"
branch = "irisnet/v0.27.0-dev1-iris"

[[constraint]]
name = "github.com/emicklei/proto"
Expand Down
11 changes: 9 additions & 2 deletions client/lcd/lcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,21 @@ func ServeLCDStartCommand(cdc *codec.Codec) *cobra.Command {
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "irislcd")
maxOpen := viper.GetInt(flagMaxOpenConnections)

listener, err := tmserver.StartHTTPServer(
listenAddr, router, logger,
listener, err := tmserver.Listen(
listenAddr,
tmserver.Config{MaxOpenConnections: maxOpen},
)
if err != nil {
return err
}

logger.Info("Starting IRISLCD service...")

err = tmserver.StartHTTPServer(listener, router, logger)
if err != nil {
return err
}

logger.Info("IRISLCD server started")

// wait forever and cleanup
Expand Down
11 changes: 10 additions & 1 deletion client/lcd/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,16 @@ func startTM(
//
// NOTE: This causes the thread to block.
func startLCD(logger log.Logger, listenAddr string, cdc *codec.Codec) (net.Listener, error) {
return tmrpc.StartHTTPServer(listenAddr, createHandler(cdc), logger, tmrpc.Config{})
listener, err := tmrpc.Listen(listenAddr, tmrpc.Config{})
if err != nil {
return nil, err
}

err = tmrpc.StartHTTPServer(listener, createHandler(cdc), logger)
if err != nil {
return nil, err
}
return listener, nil
}

// Request makes a test LCD test request. It returns a response object and a
Expand Down
16 changes: 8 additions & 8 deletions client/tendermint/rpc/validatorset.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ func ValidatorCommand() *cobra.Command {

// Validator output in bech32 format
type ValidatorOutput struct {
Address sdk.ValAddress `json:"address"` // in bech32
PubKey string `json:"pub_key"` // in bech32
Accum int64 `json:"accum"`
VotingPower int64 `json:"voting_power"`
Address sdk.ValAddress `json:"address"` // in bech32
PubKey string `json:"pub_key"` // in bech32
ProposerPriority int64 `json:"proposer_priority"`
VotingPower int64 `json:"voting_power"`
}

// Validators at a certain height output in bech32 format
Expand All @@ -54,10 +54,10 @@ func bech32ValidatorOutput(validator *tmtypes.Validator) (ValidatorOutput, error
}

return ValidatorOutput{
Address: sdk.ValAddress(validator.Address),
PubKey: bechValPubkey,
Accum: validator.Accum,
VotingPower: validator.VotingPower,
Address: sdk.ValAddress(validator.Address),
PubKey: bechValPubkey,
ProposerPriority: validator.ProposerPriority,
VotingPower: validator.VotingPower,
}, nil
}

Expand Down
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
- "26656-26657:26656-26657"
volumes:
- ./build:/home
command: /bin/bash -c 'cd /home/nodecluster/node0 && ../../iris start --home iris'
command: /bin/bash -c 'cd /home/nodecluster/node0 && ../../iris start --home iris --log_level info'
networks:
localnet:
ipv4_address: 192.168.10.2
Expand All @@ -20,7 +20,7 @@ services:
- "26659-26660:26656-26657"
volumes:
- ./build:/home
command: /bin/bash -c 'cd /home/nodecluster/node1 && ../../iris start --home iris'
command: /bin/bash -c 'cd /home/nodecluster/node1 && ../../iris start --home iris --log_level info'
networks:
localnet:
ipv4_address: 192.168.10.3
Expand All @@ -32,7 +32,7 @@ services:
- "26661-26662:26656-26657"
volumes:
- ./build:/home
command: /bin/bash -c 'cd /home/nodecluster/node2 && ../../iris start --home iris'
command: /bin/bash -c 'cd /home/nodecluster/node2 && ../../iris start --home iris --log_level info'
networks:
localnet:
ipv4_address: 192.168.10.4
Expand All @@ -44,7 +44,7 @@ services:
- "26663-26664:26656-26657"
volumes:
- ./build:/home
command: /bin/bash -c 'cd /home/nodecluster/node3 && ../../iris start --home iris'
command: /bin/bash -c 'cd /home/nodecluster/node3 && ../../iris start --home iris --log_level info'
networks:
localnet:
ipv4_address: 192.168.10.5
Expand Down
2 changes: 1 addition & 1 deletion modules/gov/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) (resTags sdk.Tags) {
resTags = sdk.NewTags()

if ctx.BlockHeight() == keeper.GetTerminatorHeight(ctx) {
resTags = resTags.AppendTag(tmstate.TerminateTagKey,[]byte(tmstate.TerminateTagValue))
resTags = resTags.AppendTag(tmstate.HaltTagKey,[]byte(tmstate.HaltTagValue))
logger.Info(fmt.Sprintf("Terminator Start!!!"))
}

Expand Down
11 changes: 7 additions & 4 deletions modules/slashing/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, vs sdk.ValidatorSet, paramspa

// handle a validator signing two blocks at the same height
// power: power of the double-signing validator at the height of infraction
func (k Keeper) handleDoubleSign(ctx sdk.Context, addr crypto.Address, infractionHeight int64, timestamp time.Time, power int64) {
func (k Keeper) handleDoubleSign(ctx sdk.Context, addr crypto.Address, infractionHeight int64, timestamp time.Time, power int64) (tags sdk.Tags) {
logger := ctx.Logger().With("module", "x/slashing")
time := ctx.BlockHeader().Time
age := time.Sub(timestamp)
Expand Down Expand Up @@ -83,7 +83,7 @@ func (k Keeper) handleDoubleSign(ctx sdk.Context, addr crypto.Address, infractio
// ABCI, and now received as evidence.
// The revisedFraction (which is the new fraction to be slashed) is passed
// in separately to separately slash unbonding and rebonding delegations.
k.validatorSet.Slash(ctx, consAddr, distributionHeight, power, revisedFraction)
tags = k.validatorSet.Slash(ctx, consAddr, distributionHeight, power, revisedFraction)

// Jail validator if not already jailed
if !validator.GetJailed() {
Expand All @@ -97,11 +97,12 @@ func (k Keeper) handleDoubleSign(ctx sdk.Context, addr crypto.Address, infractio
}
signInfo.JailedUntil = time.Add(k.DoubleSignUnbondDuration(ctx))
k.setValidatorSigningInfo(ctx, consAddr, signInfo)
return
}

// handle a validator signature, must be called once per validator per block
// TODO refactor to take in a consensus address, additionally should maybe just take in the pubkey too
func (k Keeper) handleValidatorSignature(ctx sdk.Context, addr crypto.Address, power int64, signed bool) {
func (k Keeper) handleValidatorSignature(ctx sdk.Context, addr crypto.Address, power int64, signed bool) (tags sdk.Tags) {
logger := ctx.Logger().With("module", "x/slashing")
height := ctx.BlockHeight()
consAddr := sdk.ConsAddress(addr)
Expand Down Expand Up @@ -153,7 +154,8 @@ func (k Keeper) handleValidatorSignature(ctx sdk.Context, addr crypto.Address, p
// i.e. at the end of the pre-genesis block (none) = at the beginning of the genesis block.
// That's fine since this is just used to filter unbonding delegations & redelegations.
distributionHeight := height - stake.ValidatorUpdateDelay - 1
k.validatorSet.Slash(ctx, consAddr, distributionHeight, power, k.SlashFractionDowntime(ctx))
slashTags := k.validatorSet.Slash(ctx, consAddr, distributionHeight, power, k.SlashFractionDowntime(ctx))
tags = tags.AppendTags(slashTags)
k.validatorSet.Jail(ctx, consAddr)
signInfo.JailedUntil = ctx.BlockHeader().Time.Add(k.DowntimeUnbondDuration(ctx))
// We need to reset the counter & array so that the validator won't be immediately slashed for downtime upon rebonding.
Expand All @@ -169,6 +171,7 @@ func (k Keeper) handleValidatorSignature(ctx sdk.Context, addr crypto.Address, p

// Set the updated signing info
k.setValidatorSigningInfo(ctx, consAddr, signInfo)
return
}

func (k Keeper) addPubkey(ctx sdk.Context, pubkey crypto.PubKey) {
Expand Down
6 changes: 4 additions & 2 deletions modules/slashing/tick.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, sk Keeper) (tags
// store whether or not they have actually signed it and slash/unbond any
// which have missed too many blocks in a row (downtime slashing)
for _, voteInfo := range req.LastCommitInfo.GetVotes() {
sk.handleValidatorSignature(ctx, voteInfo.Validator.Address, voteInfo.Validator.Power, voteInfo.SignedLastBlock)
absenceSlashTags := sk.handleValidatorSignature(ctx, voteInfo.Validator.Address, voteInfo.Validator.Power, voteInfo.SignedLastBlock)
tags = tags.AppendTags(absenceSlashTags)
}

// Iterate through any newly discovered evidence of infraction
Expand All @@ -30,7 +31,8 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, sk Keeper) (tags
for _, evidence := range req.ByzantineValidators {
switch evidence.Type {
case tmtypes.ABCIEvidenceTypeDuplicateVote:
sk.handleDoubleSign(ctx, evidence.Validator.Address, evidence.Height, evidence.Time, evidence.Validator.Power)
doubleSignSlashTag := sk.handleDoubleSign(ctx, evidence.Validator.Address, evidence.Height, evidence.Time, evidence.Validator.Power)
tags = tags.AppendTags(doubleSignSlashTag)
default:
ctx.Logger().With("module", "x/slashing").Error(fmt.Sprintf("ignored unknown evidence type: %s", evidence.Type))
}
Expand Down
Loading

0 comments on commit 14bdb81

Please sign in to comment.