forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ethereum#35 from QuarkChain/tm_w3q_multi_val
integrate eth wallet for chamber validator
- Loading branch information
Showing
9 changed files
with
223 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package tendermint | ||
|
||
import ( | ||
"context" | ||
|
||
pbft "github.com/QuarkChain/go-minimal-pbft/consensus" | ||
"github.com/ethereum/go-ethereum/accounts" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
) | ||
|
||
type EthPrivValidator struct { | ||
signer common.Address // Ethereum address of the signing key | ||
signFn SignerFn // Signer function to authorize hashes with | ||
} | ||
|
||
type EthPubKey struct { | ||
signer common.Address | ||
} | ||
|
||
func (pubkey *EthPubKey) Type() string { | ||
return "ETH_PUBKEY" | ||
} | ||
|
||
func (pubkey *EthPubKey) Address() common.Address { | ||
return pubkey.signer | ||
} | ||
|
||
func (pubkey *EthPubKey) VerifySignature(msg []byte, sig []byte) bool { | ||
pub, err := crypto.Ecrecover(msg, sig) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
if len(pub) == 0 || pub[0] != 4 { | ||
return false | ||
} | ||
|
||
var signer common.Address | ||
copy(signer[:], crypto.Keccak256(pub[1:])[12:]) | ||
return signer == pubkey.signer | ||
} | ||
|
||
func NewEthPrivValidator(signer common.Address, signFn SignerFn) pbft.PrivValidator { | ||
return &EthPrivValidator{signer: signer, signFn: signFn} | ||
} | ||
|
||
func (pv *EthPrivValidator) Address() common.Address { | ||
return pv.signer | ||
} | ||
|
||
func (pv *EthPrivValidator) GetPubKey(context.Context) (pbft.PubKey, error) { | ||
return &EthPubKey{signer: pv.signer}, nil | ||
} | ||
|
||
func (pv *EthPrivValidator) SignVote(ctx context.Context, chainId string, vote *pbft.Vote) error { | ||
vote.TimestampMs = uint64(pbft.CanonicalNowMs()) | ||
b := vote.VoteSignBytes(chainId) | ||
|
||
sign, err := pv.signFn(accounts.Account{Address: pv.signer}, accounts.MimetypeClique, b) | ||
vote.Signature = sign | ||
|
||
return err | ||
} | ||
|
||
func (pv *EthPrivValidator) SignProposal(ctx context.Context, chainID string, proposal *pbft.Proposal) error { | ||
// TODO: sanity check | ||
b := proposal.ProposalSignBytes(chainID) | ||
|
||
sign, err := pv.signFn(accounts.Account{Address: pv.signer}, accounts.MimetypeClique, b) | ||
proposal.Signature = sign | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package params | ||
|
||
import "time" | ||
|
||
// ConsensusConfig defines the configuration for the Tendermint consensus service, | ||
// including timeouts and details about the WAL and the block structure. | ||
type ConsensusConfig struct { | ||
RootDir string `mapstructure:"home"` | ||
WalPath string `mapstructure:"wal-file"` | ||
WalFile string // overrides WalPath if set | ||
|
||
// TODO: remove timeout configs, these should be global not local | ||
// How long we wait for a proposal block before prevoting nil | ||
TimeoutPropose time.Duration `mapstructure:"timeout-propose"` | ||
// How much timeout-propose increases with each round | ||
TimeoutProposeDelta time.Duration `mapstructure:"timeout-propose-delta"` | ||
// How long we wait after receiving +2/3 prevotes for “anything” (ie. not a single block or nil) | ||
TimeoutPrevote time.Duration `mapstructure:"timeout-prevote"` | ||
// How much the timeout-prevote increases with each round | ||
TimeoutPrevoteDelta time.Duration `mapstructure:"timeout-prevote-delta"` | ||
// How long we wait after receiving +2/3 precommits for “anything” (ie. not a single block or nil) | ||
TimeoutPrecommit time.Duration `mapstructure:"timeout-precommit"` | ||
// How much the timeout-precommit increases with each round | ||
TimeoutPrecommitDelta time.Duration `mapstructure:"timeout-precommit-delta"` | ||
// How long we wait after committing a block, before starting on the new | ||
// height (this gives us a chance to receive some more precommits, even | ||
// though we already have +2/3). | ||
TimeoutCommit time.Duration `mapstructure:"timeout-commit"` | ||
|
||
// Make progress as soon as we have all the precommits (as if TimeoutCommit = 0) | ||
SkipTimeoutCommit bool `mapstructure:"skip-timeout-commit"` | ||
|
||
// Reactor sleep duration parameters | ||
PeerGossipSleepDuration time.Duration `mapstructure:"peer-gossip-sleep-duration"` | ||
PeerQueryMaj23SleepDuration time.Duration `mapstructure:"peer-query-maj23-sleep-duration"` | ||
|
||
ConsensusSyncRequestDuration time.Duration | ||
|
||
DoubleSignCheckHeight uint64 `mapstructure:"double-sign-check-height"` | ||
} | ||
|
||
func NewDefaultConsesusConfig() *ConsensusConfig { | ||
// Config from tendermint except TimeoutCommit is 5s (original 1s) | ||
return &ConsensusConfig{ | ||
// WalPath: filepath.Join(defaultDataDir, "cs.wal", "wal"), | ||
TimeoutPropose: 3000 * time.Millisecond, | ||
TimeoutProposeDelta: 500 * time.Millisecond, | ||
TimeoutPrevote: 1000 * time.Millisecond, | ||
TimeoutPrevoteDelta: 500 * time.Millisecond, | ||
TimeoutPrecommit: 1000 * time.Millisecond, | ||
TimeoutPrecommitDelta: 500 * time.Millisecond, | ||
TimeoutCommit: 5000 * time.Millisecond, | ||
SkipTimeoutCommit: false, | ||
PeerGossipSleepDuration: 100 * time.Millisecond, | ||
PeerQueryMaj23SleepDuration: 2000 * time.Millisecond, | ||
DoubleSignCheckHeight: uint64(0), | ||
ConsensusSyncRequestDuration: 500 * time.Millisecond, | ||
} | ||
} | ||
|
||
// Propose returns the amount of time to wait for a proposal | ||
func (cfg *ConsensusConfig) Propose(round int32) time.Duration { | ||
return time.Duration( | ||
cfg.TimeoutPropose.Nanoseconds()+cfg.TimeoutProposeDelta.Nanoseconds()*int64(round), | ||
) * time.Nanosecond | ||
} | ||
|
||
// Prevote returns the amount of time to wait for straggler votes after receiving any +2/3 prevotes | ||
func (cfg *ConsensusConfig) Prevote(round int32) time.Duration { | ||
return time.Duration( | ||
cfg.TimeoutPrevote.Nanoseconds()+cfg.TimeoutPrevoteDelta.Nanoseconds()*int64(round), | ||
) * time.Nanosecond | ||
} | ||
|
||
// Precommit returns the amount of time to wait for straggler votes after receiving any +2/3 precommits | ||
func (cfg *ConsensusConfig) Precommit(round int32) time.Duration { | ||
return time.Duration( | ||
cfg.TimeoutPrecommit.Nanoseconds()+cfg.TimeoutPrecommitDelta.Nanoseconds()*int64(round), | ||
) * time.Nanosecond | ||
} | ||
|
||
// Commit returns the amount of time to wait for straggler votes after receiving +2/3 precommits | ||
// for a single block (ie. a commit). | ||
func (cfg *ConsensusConfig) Commit(t time.Time) time.Time { | ||
return t.Add(cfg.TimeoutCommit) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters