mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 14:52:17 +00:00
address comments in progress
This commit is contained in:
parent
29a7bea364
commit
f89daec13e
@ -45,7 +45,7 @@ func NewPersistentKVStoreApplication(dbDir string) *PersistentKVStoreApplication
|
||||
|
||||
return &PersistentKVStoreApplication{
|
||||
app: &KVStoreApplication{state: state},
|
||||
relation: make(map[string]types.PubKey),
|
||||
valAddrToPubKeyMap: make(map[string]types.PubKey),
|
||||
logger: log.NewNopLogger(),
|
||||
}
|
||||
}
|
||||
@ -122,8 +122,11 @@ func (app *PersistentKVStoreApplication) BeginBlock(req types.RequestBeginBlock)
|
||||
switch ev.Type {
|
||||
case tmtypes.ABCIEvidenceTypeDuplicateVote:
|
||||
// decrease voting power by 1
|
||||
if ev.TotalVotingPower == 0 {
|
||||
continue
|
||||
}
|
||||
app.updateValidator(types.ValidatorUpdate{
|
||||
PubKey: app.relation[string(ev.Validator.Address)],
|
||||
PubKey: app.valAddrToPubKeyMap[string(ev.Validator.Address)],
|
||||
Power: ev.TotalVotingPower - 1,
|
||||
})
|
||||
}
|
||||
@ -212,7 +215,7 @@ func (app *PersistentKVStoreApplication) updateValidator(v types.ValidatorUpdate
|
||||
}
|
||||
app.app.state.db.Delete(key)
|
||||
|
||||
delete(app.relation, string(pubkey.Address()))
|
||||
delete(app.valAddrToPubKeyMap, string(pubkey.Address()))
|
||||
|
||||
} else {
|
||||
// add or update validator
|
||||
@ -224,7 +227,7 @@ func (app *PersistentKVStoreApplication) updateValidator(v types.ValidatorUpdate
|
||||
}
|
||||
app.app.state.db.Set(key, value.Bytes())
|
||||
|
||||
app.relation[string(pubkey.Address())] = v.PubKey
|
||||
app.valAddrToPubKeyMap[string(pubkey.Address())] = v.PubKey
|
||||
}
|
||||
|
||||
// we only update the changes array if we successfully updated the tree
|
||||
|
@ -52,7 +52,6 @@ type SignClient interface {
|
||||
Validators(height *int64) (*ctypes.ResultValidators, error)
|
||||
Tx(hash []byte, prove bool) (*ctypes.ResultTx, error)
|
||||
TxSearch(query string, prove bool, page, perPage int) (*ctypes.ResultTxSearch, error)
|
||||
BroadcastDuplicateVote(pubkey crypto.PubKey, vote1 types.Vote, vote2 types.Vote) (*ctypes.ResultBroadcastDuplicateVote, error)
|
||||
}
|
||||
|
||||
// HistoryClient shows us data from genesis to now in large chunks.
|
||||
@ -76,6 +75,7 @@ type Client interface {
|
||||
HistoryClient
|
||||
StatusClient
|
||||
EventsClient
|
||||
EvidenceClient
|
||||
}
|
||||
|
||||
// NetworkClient is general info about the network state. May not
|
||||
@ -101,3 +101,8 @@ type MempoolClient interface {
|
||||
UnconfirmedTxs(limit int) (*ctypes.ResultUnconfirmedTxs, error)
|
||||
NumUnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error)
|
||||
}
|
||||
|
||||
// EvidenceClient is used for submitting evidence for malicious behaviours
|
||||
type EvidenceClient interface {
|
||||
BroadcastDuplicateVote(pubkey crypto.PubKey, vote1 types.Vote, vote2 types.Vote) (*ctypes.ResultBroadcastDuplicateVote, error)
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ type Client struct {
|
||||
client.HistoryClient
|
||||
client.StatusClient
|
||||
client.EventsClient
|
||||
client.EvidenceClient
|
||||
cmn.Service
|
||||
}
|
||||
|
||||
@ -134,3 +135,7 @@ func (c Client) Commit(height *int64) (*ctypes.ResultCommit, error) {
|
||||
func (c Client) Validators(height *int64) (*ctypes.ResultValidators, error) {
|
||||
return core.Validators(height)
|
||||
}
|
||||
|
||||
func (c Client) BroadcastEvidence(pubkey crypto.PubKey, vote1, vote2 types.Vote) (*ctypes.ResultBroadcastDuplicateVote, error) {
|
||||
return core.BroadcastDuplicateVote(pubkey, vote1, vote2)
|
||||
}
|
||||
|
@ -567,7 +567,8 @@ func TestBroadcastDuplicateVote(t *testing.T) {
|
||||
|
||||
for _, fake := range fakes {
|
||||
_, err := c.BroadcastDuplicateVote(fake.PubKey, *fake.VoteA, *fake.VoteB)
|
||||
require.Error(t, err, "Broadcasting fake evidence succeed", fake.String())
|
||||
require.Error(t, err, "Broadcasting fake evidence succeed: %s", fake.String())
|
||||
require.True(t, strings.HasPrefix(err.Error(), "Error broadcasting evidence, adding evidence"), "Broadcasting fake evidence failed on HTTP call: %s", fake.String())
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
// ### Query Parameters
|
||||
// ### Broadcast Duplicate Vote Parameters
|
||||
//
|
||||
// | Parameter | Type | Default | Required | Description |
|
||||
// |-----------+--------+---------+----------+-------------------------------|
|
||||
@ -16,14 +16,7 @@ import (
|
||||
// | vote1 | Vote | nil | true | First vote |
|
||||
// | vote2 | Vote | nil | true | Second vote |
|
||||
func BroadcastDuplicateVote(pubkey crypto.PubKey, vote1 types.Vote, vote2 types.Vote) (*ctypes.ResultBroadcastDuplicateVote, error) {
|
||||
chainID := p2pTransport.NodeInfo().Network
|
||||
ev := &types.DuplicateVoteEvidence{pubkey, &vote1, &vote2}
|
||||
if err := vote1.Verify(chainID, pubkey); err != nil {
|
||||
return nil, fmt.Errorf("Error broadcasting evidence, invalid vote1: %v", err)
|
||||
}
|
||||
if err := vote2.Verify(chainID, pubkey); err != nil {
|
||||
return nil, fmt.Errorf("Error broadcasting evidence, invalid vote2: %v", err)
|
||||
}
|
||||
|
||||
err := evidencePool.AddEvidence(ev)
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user