Skip to content

Commit

Permalink
Merge pull request #5 from wukongcheng/silei/logs
Browse files Browse the repository at this point in the history
 add log for slash the malefactor proposer
  • Loading branch information
MrXJC authored Jan 18, 2019
2 parents 4b63605 + 13bbbc6 commit 58662d1
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 102 deletions.
20 changes: 1 addition & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,11 @@ COMMIT_HASH := $(shell git rev-parse --short HEAD)

InvariantLevel := $(shell if [ -z ${InvariantLevel} ]; then echo "panic"; else echo ${InvariantLevel}; fi)
NetworkType := $(shell if [ -z ${NetworkType} ]; then echo "testnet"; else echo ${NetworkType}; fi)
Bech32PrefixAccAddr := $(shell if [ -z ${Bech32PrefixAccAddr} ]; then echo "faa"; else echo ${Bech32PrefixAccAddr}; fi)
Bech32PrefixAccPub := $(shell if [ -z ${Bech32PrefixAccPub} ]; then echo "fap"; else echo ${Bech32PrefixAccPub}; fi)
Bech32PrefixValAddr := $(shell if [ -z ${Bech32PrefixValAddr} ]; then echo "fva"; else echo ${Bech32PrefixValAddr}; fi)
Bech32PrefixValPub := $(shell if [ -z ${Bech32PrefixValPub} ]; then echo "fvp"; else echo ${Bech32PrefixValPub}; fi)
Bech32PrefixConsAddr := $(shell if [ -z ${Bech32PrefixConsAddr} ]; then echo "fca"; else echo ${Bech32PrefixConsAddr}; fi)
Bech32PrefixConsPub := $(shell if [ -z ${Bech32PrefixConsPub} ]; then echo "fcp"; else echo ${Bech32PrefixConsPub}; fi)

BUILD_FLAGS = -ldflags "\
-X github.com/irisnet/irishub/version.GitCommit=${COMMIT_HASH} \
-X github.com/irisnet/irishub/types.InvariantLevel=${InvariantLevel} \
-X github.com/irisnet/irishub/types.NetworkType=${NetworkType} \
-X github.com/irisnet/irishub/types.Bech32PrefixAccAddr=${Bech32PrefixAccAddr} \
-X github.com/irisnet/irishub/types.Bech32PrefixAccPub=${Bech32PrefixAccPub} \
-X github.com/irisnet/irishub/types.Bech32PrefixValAddr=${Bech32PrefixValAddr} \
-X github.com/irisnet/irishub/types.Bech32PrefixValPub=${Bech32PrefixValPub} \
-X github.com/irisnet/irishub/types.Bech32PrefixConsAddr=${Bech32PrefixConsAddr} \
-X github.com/irisnet/irishub/types.Bech32PrefixConsPub=${Bech32PrefixConsPub}"
-X github.com/irisnet/irishub/types.NetworkType=${NetworkType}"

########################################
### Tools & dependencies
Expand All @@ -35,12 +23,6 @@ echo_bech32_prefix:
@echo "\"source scripts/setProdEnv.sh\" to set compile environment variables for your product, or default values will be applied"
@echo InvariantLevel=${InvariantLevel}
@echo NetworkType=${NetworkType}
@echo Bech32PrefixAccAddr=${Bech32PrefixAccAddr}
@echo Bech32PrefixAccPub=${Bech32PrefixAccPub}
@echo Bech32PrefixValAddr=${Bech32PrefixValAddr}
@echo Bech32PrefixValPub=${Bech32PrefixValPub}
@echo Bech32PrefixConsAddr=${Bech32PrefixConsAddr}
@echo Bech32PrefixConsPub=${Bech32PrefixConsPub}

check_tools:
cd scripts && $(MAKE) check_tools
Expand Down
8 changes: 7 additions & 1 deletion modules/slashing/tick.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
sdk "github.com/irisnet/irishub/types"
abci "github.com/tendermint/tendermint/abci/types"
tmtypes "github.com/tendermint/tendermint/types"
"github.com/tendermint/tendermint/crypto"
)

// slashing begin block functionality
Expand Down Expand Up @@ -34,7 +35,7 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, sk Keeper) (tags
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))
ctx.Logger().With("module", "iris/slashing").Error(fmt.Sprintf("ignored unknown evidence type: %s", evidence.Type))
}
}

Expand All @@ -50,6 +51,11 @@ func EndBlocker(ctx sdk.Context, req abci.RequestEndBlock, sk Keeper) (tags sdk.
tags = sdk.NewTags("height", heightBytes)

if int64(ctx.CheckValidNum()) < ctx.BlockHeader().NumTxs {
ctx.Logger().With("module", "iris/slashing").
Info("the malefactor proposer proposed a invalid block",
"proposer address", crypto.Address(ctx.BlockHeader().ProposerAddress).String(),
"block height", ctx.BlockHeight())

proposalCensorshipTag := sk.handleProposerCensorship(ctx,
ctx.BlockHeader().ProposerAddress,
ctx.BlockHeight())
Expand Down
8 changes: 0 additions & 8 deletions scripts/setProdEnv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
# Network type: testnet, mainnet
export NetworkType="mainnet"

# Bech32 prefixes
export Bech32PrefixAccAddr="iaa"
export Bech32PrefixAccPub="iap"
export Bech32PrefixValAddr="iva"
export Bech32PrefixValPub="ivp"
export Bech32PrefixConsAddr="ica"
export Bech32PrefixConsPub="icp"

# Disable invariant checking: "no"
# Panic on invariant failure: "panic"
# Print error message on invariant failure: "error"
Expand Down
12 changes: 6 additions & 6 deletions types/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ var invalidStrs = []string{
"hello, world!",
"0xAA",
"AAA",
types.Bech32PrefixAccAddr + "AB0C",
types.Bech32PrefixAccPub + "1234",
types.Bech32PrefixValAddr + "5678",
types.Bech32PrefixValPub + "BBAB",
types.Bech32PrefixConsAddr + "FF04",
types.Bech32PrefixConsPub + "6789",
"faa" + "AB0C",
"fap" + "1234",
"fva" + "5678",
"fvp" + "BBAB",
"fca" + "FF04",
"fcp" + "6789",
}

func testMarshal(t *testing.T, original interface{}, res interface{}, marshal func() ([]byte, error), unmarshal func([]byte) error) {
Expand Down
92 changes: 24 additions & 68 deletions types/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package types

import (
"sync"
"fmt"
)

Expand All @@ -26,32 +25,32 @@ var (
var (
NetworkType = Testnet
InvariantLevel = InvariantPanic
Bech32PrefixAccAddr = "faa" // account address
Bech32PrefixAccPub = "fap" // account public key
Bech32PrefixValAddr = "fva" // validator operator address
Bech32PrefixValPub = "fvp" // validator operator public key
Bech32PrefixConsAddr = "fca" // consensus node address
Bech32PrefixConsPub = "fcp" // consensus node public key
)

var (
// Initializing an instance of Config
config = &Config{
sealed: true,
testnetConfig = &Config{
bech32AddressPrefix: map[string]string{
"account_addr": Bech32PrefixAccAddr,
"validator_addr": Bech32PrefixValAddr,
"consensus_addr": Bech32PrefixConsAddr,
"account_pub": Bech32PrefixAccPub,
"validator_pub": Bech32PrefixValPub,
"consensus_pub": Bech32PrefixConsPub,
"account_addr": "faa",
"validator_addr": "fva",
"consensus_addr": "fca",
"account_pub": "fap",
"validator_pub": "fvp",
"consensus_pub": "fcp",
},
}
mainnetConfig = &Config{
bech32AddressPrefix: map[string]string{
"account_addr": "iaa",
"validator_addr": "iva",
"consensus_addr": "ica",
"account_pub": "iap",
"validator_pub": "ivp",
"consensus_pub": "icp",
},
}
)

type Config struct {
mtx sync.RWMutex
sealed bool
bech32AddressPrefix map[string]string
}

Expand All @@ -60,61 +59,18 @@ type Config struct {
// containing a descriptive message about what happened.
type Invariant func(ctx Context) error

/*
func InitBech32Prefix() {
config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub)
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)
config.Seal()
func SetNetworkType(networkType string) {
NetworkType = networkType
}
*/
// GetConfig returns the config instance for the SDK.
func GetConfig() *Config {
return config
}
/*
func (config *Config) assertNotSealed() {
config.mtx.Lock()
defer config.mtx.Unlock()

if config.sealed {
panic("Config is sealed")
// GetConfig returns the config instance for the corresponding network type
func GetConfig() *Config {
if NetworkType == Mainnet {
return mainnetConfig
}
return testnetConfig
}

// SetBech32PrefixForAccount builds the Config with Bech32 addressPrefix and publKeyPrefix for accounts
// and returns the config instance
func (config *Config) SetBech32PrefixForAccount(addressPrefix, pubKeyPrefix string) {
config.assertNotSealed()
config.bech32AddressPrefix["account_addr"] = addressPrefix
config.bech32AddressPrefix["account_pub"] = pubKeyPrefix
}
// SetBech32PrefixForValidator builds the Config with Bech32 addressPrefix and publKeyPrefix for validators
// and returns the config instance
func (config *Config) SetBech32PrefixForValidator(addressPrefix, pubKeyPrefix string) {
config.assertNotSealed()
config.bech32AddressPrefix["validator_addr"] = addressPrefix
config.bech32AddressPrefix["validator_pub"] = pubKeyPrefix
}
// SetBech32PrefixForConsensusNode builds the Config with Bech32 addressPrefix and publKeyPrefix for consensus nodes
// and returns the config instance
func (config *Config) SetBech32PrefixForConsensusNode(addressPrefix, pubKeyPrefix string) {
config.assertNotSealed()
config.bech32AddressPrefix["consensus_addr"] = addressPrefix
config.bech32AddressPrefix["consensus_pub"] = pubKeyPrefix
}
// Seal seals the config such that the config state could not be modified further
func (config *Config) Seal() *Config {
config.mtx.Lock()
defer config.mtx.Unlock()
config.sealed = true
return config
}
*/
// GetBech32AccountAddrPrefix returns the Bech32 prefix for account address
func (config *Config) GetBech32AccountAddrPrefix() string {
return config.bech32AddressPrefix["account_addr"]
Expand Down

0 comments on commit 58662d1

Please sign in to comment.