implementing ExecTx...

This commit is contained in:
Jae Kwon
2014-10-07 23:11:04 -07:00
parent 0c206aa748
commit 18e2d4bf48
14 changed files with 265 additions and 247 deletions

View File

@ -402,7 +402,7 @@ OUTER_LOOP:
// Signs a vote document and broadcasts it.
func (conR *ConsensusReactor) signAndBroadcastVote(rs *RoundState, vote *Vote) {
if rs.PrivValidator != nil {
rs.PrivValidator.SignVote(vote)
rs.PrivValidator.Sign(vote)
conR.conS.AddVote(vote)
msg := p2p.TypedMessage{msgTypeVote, vote}
conR.sw.Broadcast(VoteCh, msg)

View File

@ -45,8 +45,8 @@ func (pol *POL) WriteTo(w io.Writer) (n int64, err error) {
func (pol *POL) Verify(vset *ValidatorSet) error {
talliedVotingPower := uint64(0)
voteDoc := (&Vote{Height: pol.Height, Round: pol.Round,
Type: VoteTypeBare, BlockHash: pol.BlockHash}).GenDocument()
voteDoc := BinaryBytes(&Vote{Height: pol.Height, Round: pol.Round,
Type: VoteTypeBare, BlockHash: pol.BlockHash})
seenValidators := map[uint64]struct{}{}
for _, sig := range pol.Votes {
@ -59,7 +59,7 @@ func (pol *POL) Verify(vset *ValidatorSet) error {
if validator == nil {
return Errorf("Invalid validator for vote %v for POL %v", sig, pol)
}
if !validator.Verify(voteDoc, sig) {
if !validator.VerifyBytes(voteDoc, sig) {
return Errorf("Invalid signature for vote %v for POL %v", sig, pol)
}
@ -80,9 +80,9 @@ func (pol *POL) Verify(vset *ValidatorSet) error {
return Errorf("Invalid validator for commit %v for POL %v", sig, pol)
}
commitDoc := (&Vote{Height: pol.Height, Round: round,
Type: VoteTypeCommit, BlockHash: pol.BlockHash}).GenDocument() // TODO cache
if !validator.Verify(commitDoc, sig) {
commitDoc := BinaryBytes(&Vote{Height: pol.Height, Round: round,
Type: VoteTypeCommit, BlockHash: pol.BlockHash}) // TODO cache
if !validator.VerifyBytes(commitDoc, sig) {
return Errorf("Invalid signature for commit %v for POL %v", sig, pol)
}

View File

@ -13,14 +13,14 @@ type PrivValidator struct {
db *db_.LevelDB
}
// Double signing results in an error.
func (pv *PrivValidator) SignProposal(proposal *Proposal) {
//TODO: prevent double signing.
pv.SignSignable(proposal)
}
// Double signing results in an error.
func (pv *PrivValidator) SignVote(vote *Vote) {
//TODO: prevent double signing.
pv.SignSignable(vote)
// Double signing results in a panic.
func (pv *PrivValidator) Sign(o Signable) {
switch o.(type) {
case *Proposal:
//TODO: prevent double signing.
pv.PrivAccount.Sign(o.(*Proposal))
case *Vote:
//TODO: prevent double signing.
pv.PrivAccount.Sign(o.(*Vote))
}
}

View File

@ -58,14 +58,6 @@ func (p *Proposal) WriteTo(w io.Writer) (n int64, err error) {
return
}
func (p *Proposal) GenDocument() []byte {
oldSig := p.Signature
p.Signature = Signature{}
doc := BinaryBytes(p)
p.Signature = oldSig
return doc
}
func (p *Proposal) GetSignature() Signature {
return p.Signature
}

View File

@ -178,7 +178,7 @@ func (cs *ConsensusState) SetProposal(proposal *Proposal) error {
}
// Verify signature
if !cs.Proposer.Verify(proposal.GenDocument(), proposal.Signature) {
if !cs.Proposer.Verify(proposal) {
return ErrInvalidProposalSignature
}
@ -220,7 +220,7 @@ func (cs *ConsensusState) MakeProposal() {
// Make proposal
proposal := NewProposal(cs.Height, cs.Round, blockPartSet.Total(), blockPartSet.RootHash(),
polPartSet.Total(), polPartSet.RootHash())
cs.PrivValidator.SignProposal(proposal)
cs.PrivValidator.Sign(proposal)
// Set fields
cs.Proposal = proposal

View File

@ -69,7 +69,7 @@ func (vs *VoteSet) AddVote(vote *Vote) (bool, error) {
}
// Check signature.
if !val.Verify(vote.GenDocument(), vote.Signature) {
if !val.Verify(vote) {
// Bad signature.
return false, ErrVoteInvalidSignature
}