pass chainID through sign interfaces

This commit is contained in:
Ethan Buchman
2015-05-29 18:14:19 -04:00
parent 8a2d9525f0
commit 2045aee9cd
28 changed files with 122 additions and 110 deletions
+10 -10
View File
@@ -33,7 +33,7 @@ func ExecBlock(s *State, block *types.Block, blockPartsHeader types.PartSetHeade
// at an invalid state. Copy the state before calling execBlock!
func execBlock(s *State, block *types.Block, blockPartsHeader types.PartSetHeader) error {
// Basic block validation.
err := block.ValidateBasic(s.LastBlockHeight, s.LastBlockHash, s.LastBlockParts, s.LastBlockTime)
err := block.ValidateBasic(s.ChainID, s.LastBlockHeight, s.LastBlockHash, s.LastBlockParts, s.LastBlockTime)
if err != nil {
return err
}
@@ -61,7 +61,7 @@ func execBlock(s *State, block *types.Block, blockPartsHeader types.PartSetHeade
BlockHash: block.LastBlockHash,
BlockParts: block.LastBlockParts,
}
if val.PubKey.VerifyBytes(account.SignBytes(vote), commit.Signature) {
if val.PubKey.VerifyBytes(account.SignBytes(s.ChainID, vote), commit.Signature) {
sumVotingPower += val.VotingPower
return false
} else {
@@ -305,7 +305,7 @@ func ExecTx(blockCache *BlockCache, tx_ types.Tx, runCall bool, evc events.Firea
if err != nil {
return err
}
signBytes := account.SignBytes(tx)
signBytes := account.SignBytes(_s.ChainID, tx)
inTotal, err := validateInputs(accounts, signBytes, tx.Inputs)
if err != nil {
return err
@@ -353,7 +353,7 @@ func ExecTx(blockCache *BlockCache, tx_ types.Tx, runCall bool, evc events.Firea
log.Debug(Fmt("Can't find pubkey for %X", tx.Input.Address))
return err
}
signBytes := account.SignBytes(tx)
signBytes := account.SignBytes(_s.ChainID, tx)
err := validateInput(inAcc, signBytes, tx.Input)
if err != nil {
log.Debug(Fmt("validateInput failed on %X:", tx.Input.Address))
@@ -433,7 +433,7 @@ func ExecTx(blockCache *BlockCache, tx_ types.Tx, runCall bool, evc events.Firea
txCache.UpdateAccount(caller) // because we adjusted by input above, and bumped nonce maybe.
txCache.UpdateAccount(callee) // because we adjusted by input above.
vmach := vm.NewVM(txCache, params, caller.Address, account.HashSignBytes(tx))
vmach := vm.NewVM(txCache, params, caller.Address, account.HashSignBytes(_s.ChainID, tx))
vmach.SetFireable(evc)
// NOTE: Call() transfers the value from caller to callee iff call succeeds.
@@ -490,7 +490,7 @@ func ExecTx(blockCache *BlockCache, tx_ types.Tx, runCall bool, evc events.Firea
return err
}
signBytes := account.SignBytes(tx)
signBytes := account.SignBytes(_s.ChainID, tx)
inTotal, err := validateInputs(accounts, signBytes, tx.Inputs)
if err != nil {
return err
@@ -548,7 +548,7 @@ func ExecTx(blockCache *BlockCache, tx_ types.Tx, runCall bool, evc events.Firea
}
// Verify the signature
signBytes := account.SignBytes(tx)
signBytes := account.SignBytes(_s.ChainID, tx)
if !val.PubKey.VerifyBytes(signBytes, tx.Signature) {
return types.ErrTxInvalidSignature
}
@@ -573,7 +573,7 @@ func ExecTx(blockCache *BlockCache, tx_ types.Tx, runCall bool, evc events.Firea
}
// Verify the signature
signBytes := account.SignBytes(tx)
signBytes := account.SignBytes(_s.ChainID, tx)
if !val.PubKey.VerifyBytes(signBytes, tx.Signature) {
return types.ErrTxInvalidSignature
}
@@ -599,8 +599,8 @@ func ExecTx(blockCache *BlockCache, tx_ types.Tx, runCall bool, evc events.Firea
return types.ErrTxInvalidAddress
}
}
voteASignBytes := account.SignBytes(&tx.VoteA)
voteBSignBytes := account.SignBytes(&tx.VoteB)
voteASignBytes := account.SignBytes(_s.ChainID, &tx.VoteA)
voteBSignBytes := account.SignBytes(_s.ChainID, &tx.VoteB)
if !accused.PubKey.VerifyBytes(voteASignBytes, tx.VoteA.Signature) ||
!accused.PubKey.VerifyBytes(voteBSignBytes, tx.VoteB.Signature) {
return types.ErrTxInvalidSignature
+8 -8
View File
@@ -109,7 +109,7 @@ func (privVal *PrivValidator) save() {
}
// TODO: test
func (privVal *PrivValidator) SignVote(vote *types.Vote) error {
func (privVal *PrivValidator) SignVote(chainID string, vote *types.Vote) error {
privVal.mtx.Lock()
defer privVal.mtx.Unlock()
@@ -140,15 +140,15 @@ func (privVal *PrivValidator) SignVote(vote *types.Vote) error {
privVal.save()
// Sign
privVal.SignVoteUnsafe(vote)
privVal.SignVoteUnsafe(chainID, vote)
return nil
}
func (privVal *PrivValidator) SignVoteUnsafe(vote *types.Vote) {
vote.Signature = privVal.PrivKey.Sign(account.SignBytes(vote)).(account.SignatureEd25519)
func (privVal *PrivValidator) SignVoteUnsafe(chainID string, vote *types.Vote) {
vote.Signature = privVal.PrivKey.Sign(account.SignBytes(chainID, vote)).(account.SignatureEd25519)
}
func (privVal *PrivValidator) SignProposal(proposal *Proposal) error {
func (privVal *PrivValidator) SignProposal(chainID string, proposal *Proposal) error {
privVal.mtx.Lock()
defer privVal.mtx.Unlock()
if privVal.LastHeight < proposal.Height ||
@@ -162,14 +162,14 @@ func (privVal *PrivValidator) SignProposal(proposal *Proposal) error {
privVal.save()
// Sign
proposal.Signature = privVal.PrivKey.Sign(account.SignBytes(proposal)).(account.SignatureEd25519)
proposal.Signature = privVal.PrivKey.Sign(account.SignBytes(chainID, proposal)).(account.SignatureEd25519)
return nil
} else {
return errors.New(fmt.Sprintf("Attempt of duplicate signing of proposal: Height %v, Round %v", proposal.Height, proposal.Round))
}
}
func (privVal *PrivValidator) SignRebondTx(rebondTx *types.RebondTx) error {
func (privVal *PrivValidator) SignRebondTx(chainID string, rebondTx *types.RebondTx) error {
privVal.mtx.Lock()
defer privVal.mtx.Unlock()
if privVal.LastHeight < rebondTx.Height {
@@ -181,7 +181,7 @@ func (privVal *PrivValidator) SignRebondTx(rebondTx *types.RebondTx) error {
privVal.save()
// Sign
rebondTx.Signature = privVal.PrivKey.Sign(account.SignBytes(rebondTx)).(account.SignatureEd25519)
rebondTx.Signature = privVal.PrivKey.Sign(account.SignBytes(chainID, rebondTx)).(account.SignatureEd25519)
return nil
} else {
return errors.New(fmt.Sprintf("Attempt of duplicate signing of rebondTx: Height %v", rebondTx.Height))
+8 -8
View File
@@ -65,7 +65,7 @@ func TestCopyState(t *testing.T) {
func makeBlock(t *testing.T, state *State, commits []types.Commit, txs []types.Tx) *types.Block {
block := &types.Block{
Header: &types.Header{
ChainID: "tendermint_test",
ChainID: state.ChainID,
Height: state.LastBlockHeight + 1,
Time: state.LastBlockTime.Add(time.Minute),
Fees: 0,
@@ -191,7 +191,7 @@ func TestTxSequence(t *testing.T) {
for i := -1; i < 3; i++ {
sequence := acc0.Sequence + uint(i)
tx := makeSendTx(sequence)
tx.Inputs[0].Signature = privAccounts[0].Sign(tx)
tx.Inputs[0].Signature = privAccounts[0].Sign(state.ChainID, tx)
stateCopy := state.Copy()
err := execTxWithState(stateCopy, tx, true)
if i == 1 {
@@ -251,7 +251,7 @@ func TestTxs(t *testing.T) {
},
}
tx.Inputs[0].Signature = privAccounts[0].Sign(tx)
tx.Inputs[0].Signature = privAccounts[0].Sign(state.ChainID, tx)
err := execTxWithState(state, tx, true)
if err != nil {
t.Errorf("Got error in executing send transaction, %v", err)
@@ -288,8 +288,8 @@ func TestTxs(t *testing.T) {
},
},
}
tx.Signature = privAccounts[0].Sign(tx).(account.SignatureEd25519)
tx.Inputs[0].Signature = privAccounts[0].Sign(tx)
tx.Signature = privAccounts[0].Sign(state.ChainID, tx).(account.SignatureEd25519)
tx.Inputs[0].Signature = privAccounts[0].Sign(state.ChainID, tx)
err := execTxWithState(state, tx, true)
if err != nil {
t.Errorf("Got error in executing bond transaction, %v", err)
@@ -345,8 +345,8 @@ func TestAddValidator(t *testing.T) {
},
},
}
bondTx.Signature = acc0.Sign(bondTx).(account.SignatureEd25519)
bondTx.Inputs[0].Signature = acc0.Sign(bondTx)
bondTx.Signature = acc0.Sign(s0.ChainID, bondTx).(account.SignatureEd25519)
bondTx.Inputs[0].Signature = acc0.Sign(s0.ChainID, bondTx)
// Make complete block and blockParts
block0 := makeBlock(t, s0, nil, []types.Tx{bondTx})
@@ -380,7 +380,7 @@ func TestAddValidator(t *testing.T) {
BlockHash: block0.Hash(),
BlockParts: block0Parts.Header(),
}
privValidators[0].SignVote(commit0)
privValidators[0].SignVote(s0.ChainID, commit0)
block1 := makeBlock(t, s0,
[]types.Commit{
+1
View File
@@ -97,6 +97,7 @@ func RandGenesisState(numAccounts int, randBalance bool, minBalance uint64, numV
sort.Sort(PrivValidatorsByAddress(privValidators))
s0 := MakeGenesisState(db, &GenesisDoc{
GenesisTime: time.Now(),
ChainID: "tendermint_test",
Accounts: accounts,
Validators: validators,
})
+2 -2
View File
@@ -201,7 +201,7 @@ func (valSet *ValidatorSet) Iterate(fn func(index uint, val *Validator) bool) {
}
// Verify that +2/3 of the set had signed the given signBytes
func (valSet *ValidatorSet) VerifyValidation(hash []byte, parts types.PartSetHeader, height uint, v *types.Validation) error {
func (valSet *ValidatorSet) VerifyValidation(chainID string, hash []byte, parts types.PartSetHeader, height uint, v *types.Validation) error {
if valSet.Size() != uint(len(v.Commits)) {
return errors.New(Fmt("Invalid validation -- wrong set size: %v vs %v",
valSet.Size(), len(v.Commits)))
@@ -216,7 +216,7 @@ func (valSet *ValidatorSet) VerifyValidation(hash []byte, parts types.PartSetHea
continue
}
_, val := valSet.GetByIndex(uint(idx))
commitSignBytes := account.SignBytes(&types.Vote{
commitSignBytes := account.SignBytes(chainID, &types.Vote{
Height: height, Round: commit.Round, Type: types.VoteTypeCommit,
BlockHash: hash,
BlockParts: parts,