commit
7aaa33217d
|
@ -6,6 +6,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/binary"
|
||||||
|
. "github.com/tendermint/tendermint/common"
|
||||||
"github.com/tendermint/tendermint/merkle"
|
"github.com/tendermint/tendermint/merkle"
|
||||||
ptypes "github.com/tendermint/tendermint/permission/types"
|
ptypes "github.com/tendermint/tendermint/permission/types"
|
||||||
)
|
)
|
||||||
|
@ -21,8 +22,7 @@ func SignBytes(chainID string, o Signable) []byte {
|
||||||
buf, n, err := new(bytes.Buffer), new(int64), new(error)
|
buf, n, err := new(bytes.Buffer), new(int64), new(error)
|
||||||
o.WriteSignBytes(chainID, buf, n, err)
|
o.WriteSignBytes(chainID, buf, n, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
// SOMETHING HAS GONE HORRIBLY WRONG
|
PanicCrisis(err)
|
||||||
panic(err)
|
|
||||||
}
|
}
|
||||||
return buf.Bytes()
|
return buf.Bytes()
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ func GenPrivAccountFromSecret(secret []byte) *PrivAccount {
|
||||||
|
|
||||||
func GenPrivAccountFromPrivKeyBytes(privKeyBytes *[64]byte) *PrivAccount {
|
func GenPrivAccountFromPrivKeyBytes(privKeyBytes *[64]byte) *PrivAccount {
|
||||||
if len(privKeyBytes) != 64 {
|
if len(privKeyBytes) != 64 {
|
||||||
panic(Fmt("Expected 64 bytes but got %v", len(privKeyBytes)))
|
PanicSanity(Fmt("Expected 64 bytes but got %v", len(privKeyBytes)))
|
||||||
}
|
}
|
||||||
pubKeyBytes := ed25519.MakePublicKey(privKeyBytes)
|
pubKeyBytes := ed25519.MakePublicKey(privKeyBytes)
|
||||||
pubKey := PubKeyEd25519(*pubKeyBytes)
|
pubKey := PubKeyEd25519(*pubKeyBytes)
|
||||||
|
|
|
@ -40,7 +40,7 @@ func (pubKey PubKeyEd25519) Address() []byte {
|
||||||
w, n, err := new(bytes.Buffer), new(int64), new(error)
|
w, n, err := new(bytes.Buffer), new(int64), new(error)
|
||||||
binary.WriteBinary(pubKey[:], w, n, err)
|
binary.WriteBinary(pubKey[:], w, n, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
panic(*err)
|
PanicCrisis(*err)
|
||||||
}
|
}
|
||||||
// append type byte
|
// append type byte
|
||||||
encodedPubkey := append([]byte{1}, w.Bytes()...)
|
encodedPubkey := append([]byte{1}, w.Bytes()...)
|
||||||
|
|
|
@ -5,6 +5,8 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
|
. "github.com/tendermint/tendermint/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO document and maybe make it configurable.
|
// TODO document and maybe make it configurable.
|
||||||
|
@ -37,10 +39,10 @@ func ReadBinaryPtr(o interface{}, r io.Reader, n *int64, err *error) interface{}
|
||||||
rv, rt := reflect.ValueOf(o), reflect.TypeOf(o)
|
rv, rt := reflect.ValueOf(o), reflect.TypeOf(o)
|
||||||
if rv.Kind() == reflect.Ptr {
|
if rv.Kind() == reflect.Ptr {
|
||||||
readReflectBinary(rv.Elem(), rt.Elem(), Options{}, r, n, err)
|
readReflectBinary(rv.Elem(), rt.Elem(), Options{}, r, n, err)
|
||||||
return o
|
|
||||||
} else {
|
} else {
|
||||||
panic("ReadBinaryPtr expects o to be a pointer")
|
PanicSanity("ReadBinaryPtr expects o to be a pointer")
|
||||||
}
|
}
|
||||||
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
func WriteBinary(o interface{}, w io.Writer, n *int64, err *error) {
|
func WriteBinary(o interface{}, w io.Writer, n *int64, err *error) {
|
||||||
|
@ -93,10 +95,10 @@ func ReadJSONObjectPtr(o interface{}, object interface{}, err *error) interface{
|
||||||
rv, rt := reflect.ValueOf(o), reflect.TypeOf(o)
|
rv, rt := reflect.ValueOf(o), reflect.TypeOf(o)
|
||||||
if rv.Kind() == reflect.Ptr {
|
if rv.Kind() == reflect.Ptr {
|
||||||
readReflectJSON(rv.Elem(), rt.Elem(), object, err)
|
readReflectJSON(rv.Elem(), rt.Elem(), object, err)
|
||||||
return o
|
|
||||||
} else {
|
} else {
|
||||||
panic("ReadJSON(Object)Ptr expects o to be a pointer")
|
PanicSanity("ReadJSON(Object)Ptr expects o to be a pointer")
|
||||||
}
|
}
|
||||||
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
func WriteJSON(o interface{}, w io.Writer, n *int64, err *error) {
|
func WriteJSON(o interface{}, w io.Writer, n *int64, err *error) {
|
||||||
|
|
|
@ -40,8 +40,7 @@ const (
|
||||||
func BasicCodecEncoder(o interface{}, w io.Writer, n *int64, err *error) {
|
func BasicCodecEncoder(o interface{}, w io.Writer, n *int64, err *error) {
|
||||||
switch o := o.(type) {
|
switch o := o.(type) {
|
||||||
case nil:
|
case nil:
|
||||||
// SANITY CHECK
|
PanicSanity("nil type unsupported")
|
||||||
panic("nil type unsupported")
|
|
||||||
case byte:
|
case byte:
|
||||||
WriteByte(typeByte, w, n, err)
|
WriteByte(typeByte, w, n, err)
|
||||||
WriteByte(o, w, n, err)
|
WriteByte(o, w, n, err)
|
||||||
|
@ -85,8 +84,7 @@ func BasicCodecEncoder(o interface{}, w io.Writer, n *int64, err *error) {
|
||||||
WriteByte(typeTime, w, n, err)
|
WriteByte(typeTime, w, n, err)
|
||||||
WriteTime(o, w, n, err)
|
WriteTime(o, w, n, err)
|
||||||
default:
|
default:
|
||||||
// SANITY CHECK
|
PanicSanity(fmt.Sprintf("Unsupported type: %v", reflect.TypeOf(o)))
|
||||||
panic(fmt.Sprintf("Unsupported type: %v", reflect.TypeOf(o)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,8 +159,7 @@ func BasicCodecComparator(o1 interface{}, o2 interface{}) int {
|
||||||
case time.Time:
|
case time.Time:
|
||||||
return int(o1.(time.Time).UnixNano() - o2.(time.Time).UnixNano())
|
return int(o1.(time.Time).UnixNano() - o2.(time.Time).UnixNano())
|
||||||
default:
|
default:
|
||||||
// SANITY CHECK
|
PanicSanity(Fmt("Unsupported type: %v", reflect.TypeOf(o1)))
|
||||||
panic(Fmt("Unsupported type: %v", reflect.TypeOf(o1)))
|
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,8 +70,7 @@ func (info StructFieldInfo) unpack() (int, reflect.Type, Options) {
|
||||||
func GetTypeFromStructDeclaration(o interface{}) reflect.Type {
|
func GetTypeFromStructDeclaration(o interface{}) reflect.Type {
|
||||||
rt := reflect.TypeOf(o)
|
rt := reflect.TypeOf(o)
|
||||||
if rt.NumField() != 1 {
|
if rt.NumField() != 1 {
|
||||||
// SANITY CHECK
|
PanicSanity("Unexpected number of fields in struct-wrapped declaration of type")
|
||||||
panic("Unexpected number of fields in struct-wrapped declaration of type")
|
|
||||||
}
|
}
|
||||||
return rt.Field(0).Type
|
return rt.Field(0).Type
|
||||||
}
|
}
|
||||||
|
@ -79,8 +78,7 @@ func GetTypeFromStructDeclaration(o interface{}) reflect.Type {
|
||||||
func SetByteForType(typeByte byte, rt reflect.Type) {
|
func SetByteForType(typeByte byte, rt reflect.Type) {
|
||||||
typeInfo := GetTypeInfo(rt)
|
typeInfo := GetTypeInfo(rt)
|
||||||
if typeInfo.Byte != 0x00 && typeInfo.Byte != typeByte {
|
if typeInfo.Byte != 0x00 && typeInfo.Byte != typeByte {
|
||||||
// SANITY CHECK
|
PanicSanity(Fmt("Type %v already registered with type byte %X", rt, typeByte))
|
||||||
panic(Fmt("Type %v already registered with type byte %X", rt, typeByte))
|
|
||||||
}
|
}
|
||||||
typeInfo.Byte = typeByte
|
typeInfo.Byte = typeByte
|
||||||
// If pointer, we need to set it for the concrete type as well.
|
// If pointer, we need to set it for the concrete type as well.
|
||||||
|
@ -124,8 +122,7 @@ type ConcreteType struct {
|
||||||
func RegisterInterface(o interface{}, ctypes ...ConcreteType) *TypeInfo {
|
func RegisterInterface(o interface{}, ctypes ...ConcreteType) *TypeInfo {
|
||||||
it := GetTypeFromStructDeclaration(o)
|
it := GetTypeFromStructDeclaration(o)
|
||||||
if it.Kind() != reflect.Interface {
|
if it.Kind() != reflect.Interface {
|
||||||
// SANITY CHECK
|
PanicSanity("RegisterInterface expects an interface")
|
||||||
panic("RegisterInterface expects an interface")
|
|
||||||
}
|
}
|
||||||
toType := make(map[byte]reflect.Type, 0)
|
toType := make(map[byte]reflect.Type, 0)
|
||||||
toByte := make(map[reflect.Type]byte, 0)
|
toByte := make(map[reflect.Type]byte, 0)
|
||||||
|
@ -134,12 +131,10 @@ func RegisterInterface(o interface{}, ctypes ...ConcreteType) *TypeInfo {
|
||||||
typeByte := ctype.Byte
|
typeByte := ctype.Byte
|
||||||
SetByteForType(typeByte, crt)
|
SetByteForType(typeByte, crt)
|
||||||
if typeByte == 0x00 {
|
if typeByte == 0x00 {
|
||||||
// SANITY CHECK
|
PanicSanity(Fmt("Byte of 0x00 is reserved for nil (%v)", ctype))
|
||||||
panic(Fmt("Byte of 0x00 is reserved for nil (%v)", ctype))
|
|
||||||
}
|
}
|
||||||
if toType[typeByte] != nil {
|
if toType[typeByte] != nil {
|
||||||
// SANITY CHECK
|
PanicSanity(Fmt("Duplicate Byte for type %v and %v", ctype, toType[typeByte]))
|
||||||
panic(Fmt("Duplicate Byte for type %v and %v", ctype, toType[typeByte]))
|
|
||||||
}
|
}
|
||||||
toType[typeByte] = crt
|
toType[typeByte] = crt
|
||||||
toByte[crt] = typeByte
|
toByte[crt] = typeByte
|
||||||
|
@ -398,8 +393,7 @@ func readReflectBinary(rv reflect.Value, rt reflect.Type, opts Options, r io.Rea
|
||||||
rv.SetBool(num > 0)
|
rv.SetBool(num > 0)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// SANITY CHECK
|
PanicSanity(Fmt("Unknown field type %v", rt.Kind()))
|
||||||
panic(Fmt("Unknown field type %v", rt.Kind()))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -567,8 +561,7 @@ func writeReflectBinary(rv reflect.Value, rt reflect.Type, opts Options, w io.Wr
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// SANITY CHECK
|
PanicSanity(Fmt("Unknown field type %v", rt.Kind()))
|
||||||
panic(Fmt("Unknown field type %v", rt.Kind()))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -800,8 +793,7 @@ func readReflectJSON(rv reflect.Value, rt reflect.Type, o interface{}, err *erro
|
||||||
rv.SetBool(bl)
|
rv.SetBool(bl)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// SANITY CHECK
|
PanicSanity(Fmt("Unknown field type %v", rt.Kind()))
|
||||||
panic(Fmt("Unknown field type %v", rt.Kind()))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -949,8 +941,7 @@ func writeReflectJSON(rv reflect.Value, rt reflect.Type, w io.Writer, n *int64,
|
||||||
WriteTo(jsonBytes, w, n, err)
|
WriteTo(jsonBytes, w, n, err)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// SANITY CHECK
|
PanicSanity(Fmt("Unknown field type %v", rt.Kind()))
|
||||||
panic(Fmt("Unknown field type %v", rt.Kind()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,15 +4,15 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"github.com/tendermint/tendermint/Godeps/_workspace/src/code.google.com/p/go.crypto/ripemd160"
|
"github.com/tendermint/tendermint/Godeps/_workspace/src/code.google.com/p/go.crypto/ripemd160"
|
||||||
)
|
|
||||||
|
|
||||||
// THESE PANICS ARE SANITY CHECKS
|
. "github.com/tendermint/tendermint/common"
|
||||||
|
)
|
||||||
|
|
||||||
func BinaryBytes(o interface{}) []byte {
|
func BinaryBytes(o interface{}) []byte {
|
||||||
w, n, err := new(bytes.Buffer), new(int64), new(error)
|
w, n, err := new(bytes.Buffer), new(int64), new(error)
|
||||||
WriteBinary(o, w, n, err)
|
WriteBinary(o, w, n, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
panic(*err)
|
PanicSanity(*err)
|
||||||
}
|
}
|
||||||
return w.Bytes()
|
return w.Bytes()
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ func JSONBytes(o interface{}) []byte {
|
||||||
w, n, err := new(bytes.Buffer), new(int64), new(error)
|
w, n, err := new(bytes.Buffer), new(int64), new(error)
|
||||||
WriteJSON(o, w, n, err)
|
WriteJSON(o, w, n, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
panic(*err)
|
PanicSanity(*err)
|
||||||
}
|
}
|
||||||
return w.Bytes()
|
return w.Bytes()
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ func BinarySha256(o interface{}) []byte {
|
||||||
hasher, n, err := sha256.New(), new(int64), new(error)
|
hasher, n, err := sha256.New(), new(int64), new(error)
|
||||||
WriteBinary(o, hasher, n, err)
|
WriteBinary(o, hasher, n, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
panic(*err)
|
PanicSanity(*err)
|
||||||
}
|
}
|
||||||
return hasher.Sum(nil)
|
return hasher.Sum(nil)
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ func BinaryRipemd160(o interface{}) []byte {
|
||||||
hasher, n, err := ripemd160.New(), new(int64), new(error)
|
hasher, n, err := ripemd160.New(), new(int64), new(error)
|
||||||
WriteBinary(o, hasher, n, err)
|
WriteBinary(o, hasher, n, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
panic(*err)
|
PanicSanity(*err)
|
||||||
}
|
}
|
||||||
return hasher.Sum(nil)
|
return hasher.Sum(nil)
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,11 +126,9 @@ func (pool *BlockPool) PopRequest() {
|
||||||
pool.requestsMtx.Lock() // Lock
|
pool.requestsMtx.Lock() // Lock
|
||||||
defer pool.requestsMtx.Unlock()
|
defer pool.requestsMtx.Unlock()
|
||||||
|
|
||||||
// SANITY CHECK
|
|
||||||
if r := pool.requests[pool.height]; r == nil || r.block == nil {
|
if r := pool.requests[pool.height]; r == nil || r.block == nil {
|
||||||
panic("PopRequest() requires a valid block")
|
PanicSanity("PopRequest() requires a valid block")
|
||||||
}
|
}
|
||||||
// SANITY CHECK END
|
|
||||||
|
|
||||||
delete(pool.requests, pool.height)
|
delete(pool.requests, pool.height)
|
||||||
pool.height++
|
pool.height++
|
||||||
|
@ -143,11 +141,9 @@ func (pool *BlockPool) RedoRequest(height int) {
|
||||||
defer pool.requestsMtx.Unlock()
|
defer pool.requestsMtx.Unlock()
|
||||||
|
|
||||||
request := pool.requests[height]
|
request := pool.requests[height]
|
||||||
// SANITY CHECK
|
|
||||||
if request.block == nil {
|
if request.block == nil {
|
||||||
panic("Expected block to be non-nil")
|
PanicSanity("Expected block to be non-nil")
|
||||||
}
|
}
|
||||||
// SANITY CHECK END
|
|
||||||
// TODO: record this malfeasance
|
// TODO: record this malfeasance
|
||||||
// maybe punish peer on switch (an invalid block!)
|
// maybe punish peer on switch (an invalid block!)
|
||||||
pool.RemovePeer(request.peerId) // Lock on peersMtx.
|
pool.RemovePeer(request.peerId) // Lock on peersMtx.
|
||||||
|
|
|
@ -53,12 +53,10 @@ type BlockchainReactor struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBlockchainReactor(state *sm.State, store *BlockStore, sync bool) *BlockchainReactor {
|
func NewBlockchainReactor(state *sm.State, store *BlockStore, sync bool) *BlockchainReactor {
|
||||||
// SANITY CHECK
|
|
||||||
if state.LastBlockHeight != store.Height() &&
|
if state.LastBlockHeight != store.Height() &&
|
||||||
state.LastBlockHeight != store.Height()-1 { // XXX double check this logic.
|
state.LastBlockHeight != store.Height()-1 { // XXX double check this logic.
|
||||||
panic(Fmt("state (%v) and store (%v) height mismatch", state.LastBlockHeight, store.Height()))
|
PanicSanity(Fmt("state (%v) and store (%v) height mismatch", state.LastBlockHeight, store.Height()))
|
||||||
}
|
}
|
||||||
// SANITY CHECK END
|
|
||||||
requestsCh := make(chan BlockRequest, defaultChannelCapacity)
|
requestsCh := make(chan BlockRequest, defaultChannelCapacity)
|
||||||
timeoutsCh := make(chan string, defaultChannelCapacity)
|
timeoutsCh := make(chan string, defaultChannelCapacity)
|
||||||
pool := NewBlockPool(
|
pool := NewBlockPool(
|
||||||
|
@ -231,7 +229,7 @@ FOR_LOOP:
|
||||||
err := sm.ExecBlock(bcR.state, first, firstPartsHeader)
|
err := sm.ExecBlock(bcR.state, first, firstPartsHeader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO This is bad, are we zombie?
|
// TODO This is bad, are we zombie?
|
||||||
panic(Fmt("Failed to process committed block: %v", err))
|
PanicQ(Fmt("Failed to process committed block: %v", err))
|
||||||
}
|
}
|
||||||
bcR.store.SaveBlock(first, firstParts, second.LastValidation)
|
bcR.store.SaveBlock(first, firstParts, second.LastValidation)
|
||||||
bcR.state.Save()
|
bcR.state.Save()
|
||||||
|
|
|
@ -61,8 +61,7 @@ func (bs *BlockStore) LoadBlock(height int) *types.Block {
|
||||||
}
|
}
|
||||||
meta := binary.ReadBinary(&types.BlockMeta{}, r, &n, &err).(*types.BlockMeta)
|
meta := binary.ReadBinary(&types.BlockMeta{}, r, &n, &err).(*types.BlockMeta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// SOMETHING HAS GONE HORRIBLY WRONG
|
PanicCrisis(Fmt("Error reading block meta: %v", err))
|
||||||
panic(Fmt("Error reading block meta: %v", err))
|
|
||||||
}
|
}
|
||||||
bytez := []byte{}
|
bytez := []byte{}
|
||||||
for i := 0; i < meta.PartsHeader.Total; i++ {
|
for i := 0; i < meta.PartsHeader.Total; i++ {
|
||||||
|
@ -71,8 +70,7 @@ func (bs *BlockStore) LoadBlock(height int) *types.Block {
|
||||||
}
|
}
|
||||||
block := binary.ReadBinary(&types.Block{}, bytes.NewReader(bytez), &n, &err).(*types.Block)
|
block := binary.ReadBinary(&types.Block{}, bytes.NewReader(bytez), &n, &err).(*types.Block)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// SOMETHING HAS GONE HORRIBLY WRONG
|
PanicCrisis(Fmt("Error reading block: %v", err))
|
||||||
panic(Fmt("Error reading block: %v", err))
|
|
||||||
}
|
}
|
||||||
return block
|
return block
|
||||||
}
|
}
|
||||||
|
@ -86,8 +84,7 @@ func (bs *BlockStore) LoadBlockPart(height int, index int) *types.Part {
|
||||||
}
|
}
|
||||||
part := binary.ReadBinary(&types.Part{}, r, &n, &err).(*types.Part)
|
part := binary.ReadBinary(&types.Part{}, r, &n, &err).(*types.Part)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// SOMETHING HAS GONE HORRIBLY WRONG
|
PanicCrisis(Fmt("Error reading block part: %v", err))
|
||||||
panic(Fmt("Error reading block part: %v", err))
|
|
||||||
}
|
}
|
||||||
return part
|
return part
|
||||||
}
|
}
|
||||||
|
@ -101,8 +98,7 @@ func (bs *BlockStore) LoadBlockMeta(height int) *types.BlockMeta {
|
||||||
}
|
}
|
||||||
meta := binary.ReadBinary(&types.BlockMeta{}, r, &n, &err).(*types.BlockMeta)
|
meta := binary.ReadBinary(&types.BlockMeta{}, r, &n, &err).(*types.BlockMeta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// SOMETHING HAS GONE HORRIBLY WRONG
|
PanicCrisis(Fmt("Error reading block meta: %v", err))
|
||||||
panic(Fmt("Error reading block meta: %v", err))
|
|
||||||
}
|
}
|
||||||
return meta
|
return meta
|
||||||
}
|
}
|
||||||
|
@ -118,8 +114,7 @@ func (bs *BlockStore) LoadBlockValidation(height int) *types.Validation {
|
||||||
}
|
}
|
||||||
validation := binary.ReadBinary(&types.Validation{}, r, &n, &err).(*types.Validation)
|
validation := binary.ReadBinary(&types.Validation{}, r, &n, &err).(*types.Validation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// SOMETHING HAS GONE HORRIBLY WRONG
|
PanicCrisis(Fmt("Error reading validation: %v", err))
|
||||||
panic(Fmt("Error reading validation: %v", err))
|
|
||||||
}
|
}
|
||||||
return validation
|
return validation
|
||||||
}
|
}
|
||||||
|
@ -134,8 +129,7 @@ func (bs *BlockStore) LoadSeenValidation(height int) *types.Validation {
|
||||||
}
|
}
|
||||||
validation := binary.ReadBinary(&types.Validation{}, r, &n, &err).(*types.Validation)
|
validation := binary.ReadBinary(&types.Validation{}, r, &n, &err).(*types.Validation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// SOMETHING HAS GONE HORRIBLY WRONG
|
PanicCrisis(Fmt("Error reading validation: %v", err))
|
||||||
panic(Fmt("Error reading validation: %v", err))
|
|
||||||
}
|
}
|
||||||
return validation
|
return validation
|
||||||
}
|
}
|
||||||
|
@ -148,12 +142,10 @@ func (bs *BlockStore) LoadSeenValidation(height int) *types.Validation {
|
||||||
func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, seenValidation *types.Validation) {
|
func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, seenValidation *types.Validation) {
|
||||||
height := block.Height
|
height := block.Height
|
||||||
if height != bs.height+1 {
|
if height != bs.height+1 {
|
||||||
// SANITY CHECK
|
PanicSanity(Fmt("BlockStore can only save contiguous blocks. Wanted %v, got %v", bs.height+1, height))
|
||||||
panic(Fmt("BlockStore can only save contiguous blocks. Wanted %v, got %v", bs.height+1, height))
|
|
||||||
}
|
}
|
||||||
if !blockParts.IsComplete() {
|
if !blockParts.IsComplete() {
|
||||||
// SANITY CHECK
|
PanicSanity(Fmt("BlockStore can only save complete block part sets"))
|
||||||
panic(Fmt("BlockStore can only save complete block part sets"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save block meta
|
// Save block meta
|
||||||
|
@ -182,11 +174,9 @@ func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bs *BlockStore) saveBlockPart(height int, index int, part *types.Part) {
|
func (bs *BlockStore) saveBlockPart(height int, index int, part *types.Part) {
|
||||||
// SANITY CHECK
|
|
||||||
if height != bs.height+1 {
|
if height != bs.height+1 {
|
||||||
panic(Fmt("BlockStore can only save contiguous blocks. Wanted %v, got %v", bs.height+1, height))
|
PanicSanity(Fmt("BlockStore can only save contiguous blocks. Wanted %v, got %v", bs.height+1, height))
|
||||||
}
|
}
|
||||||
// SANITY CHECK END
|
|
||||||
partBytes := binary.BinaryBytes(part)
|
partBytes := binary.BinaryBytes(part)
|
||||||
bs.db.Set(calcBlockPartKey(height, index), partBytes)
|
bs.db.Set(calcBlockPartKey(height, index), partBytes)
|
||||||
}
|
}
|
||||||
|
@ -220,8 +210,7 @@ type BlockStoreStateJSON struct {
|
||||||
func (bsj BlockStoreStateJSON) Save(db dbm.DB) {
|
func (bsj BlockStoreStateJSON) Save(db dbm.DB) {
|
||||||
bytes, err := json.Marshal(bsj)
|
bytes, err := json.Marshal(bsj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// SANITY CHECK
|
PanicSanity(Fmt("Could not marshal state bytes: %v", err))
|
||||||
panic(Fmt("Could not marshal state bytes: %v", err))
|
|
||||||
}
|
}
|
||||||
db.Set(blockStoreKey, bytes)
|
db.Set(blockStoreKey, bytes)
|
||||||
}
|
}
|
||||||
|
@ -236,8 +225,7 @@ func LoadBlockStoreStateJSON(db dbm.DB) BlockStoreStateJSON {
|
||||||
bsj := BlockStoreStateJSON{}
|
bsj := BlockStoreStateJSON{}
|
||||||
err := json.Unmarshal(bytes, &bsj)
|
err := json.Unmarshal(bytes, &bsj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// SOMETHING HAS GONE HORRIBLY WRONG
|
PanicCrisis(Fmt("Could not unmarshal bytes: %X", bytes))
|
||||||
panic(Fmt("Could not unmarshal bytes: %X", bytes))
|
|
||||||
}
|
}
|
||||||
return bsj
|
return bsj
|
||||||
}
|
}
|
||||||
|
|
|
@ -209,7 +209,7 @@ func (bA *BitArray) PickRandom() (int, bool) {
|
||||||
return 64*elemIdx + bitIdx, true
|
return 64*elemIdx + bitIdx, true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
panic("should not happen")
|
PanicSanity("should not happen")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Special case for last elem, to ignore straggler bits
|
// Special case for last elem, to ignore straggler bits
|
||||||
|
|
|
@ -16,3 +16,30 @@ func (se StackError) String() string {
|
||||||
func (se StackError) Error() string {
|
func (se StackError) Error() string {
|
||||||
return se.String()
|
return se.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// panic wrappers
|
||||||
|
|
||||||
|
// A panic resulting from a sanity check means there is a programmer error
|
||||||
|
// and some gaurantee is not satisfied.
|
||||||
|
func PanicSanity(v interface{}) {
|
||||||
|
panic(Fmt("Paniced on a Sanity Check: %v", v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// A panic here means something has gone horribly wrong, in the form of data corruption or
|
||||||
|
// failure of the operating system. In a correct/healthy system, these should never fire.
|
||||||
|
// If they do, it's indicative of a much more serious problem.
|
||||||
|
func PanicCrisis(v interface{}) {
|
||||||
|
panic(Fmt("Paniced on a Crisis: %v", v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Indicates a failure of consensus. Someone was malicious or something has
|
||||||
|
// gone horribly wrong. These should really boot us into an "emergency-recover" mode
|
||||||
|
func PanicConsensus(v interface{}) {
|
||||||
|
panic(Fmt("Paniced on a Consensus Failure: %v", v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// For those times when we're not sure if we should panic
|
||||||
|
func PanicQ(v interface{}) {
|
||||||
|
panic(Fmt("Paniced questionably: %v", v))
|
||||||
|
}
|
||||||
|
|
|
@ -134,7 +134,7 @@ func CRandBytes(numBytes int) []byte {
|
||||||
b := make([]byte, numBytes)
|
b := make([]byte, numBytes)
|
||||||
_, err := crand.Read(b)
|
_, err := crand.Read(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
PanicCrisis(err)
|
||||||
}
|
}
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ func (hvs *HeightVoteSet) SetRound(round int) {
|
||||||
hvs.mtx.Lock()
|
hvs.mtx.Lock()
|
||||||
defer hvs.mtx.Unlock()
|
defer hvs.mtx.Unlock()
|
||||||
if hvs.round != 0 && (round < hvs.round+1) {
|
if hvs.round != 0 && (round < hvs.round+1) {
|
||||||
panic("SetRound() must increment hvs.round")
|
PanicSanity("SetRound() must increment hvs.round")
|
||||||
}
|
}
|
||||||
for r := hvs.round + 1; r <= round; r++ {
|
for r := hvs.round + 1; r <= round; r++ {
|
||||||
if _, ok := hvs.roundVoteSets[r]; ok {
|
if _, ok := hvs.roundVoteSets[r]; ok {
|
||||||
|
@ -76,7 +76,7 @@ func (hvs *HeightVoteSet) SetRound(round int) {
|
||||||
|
|
||||||
func (hvs *HeightVoteSet) addRound(round int) {
|
func (hvs *HeightVoteSet) addRound(round int) {
|
||||||
if _, ok := hvs.roundVoteSets[round]; ok {
|
if _, ok := hvs.roundVoteSets[round]; ok {
|
||||||
panic("addRound() for an existing round")
|
PanicSanity("addRound() for an existing round")
|
||||||
}
|
}
|
||||||
log.Info("addRound(round)", "round", round)
|
log.Info("addRound(round)", "round", round)
|
||||||
prevotes := NewVoteSet(hvs.height, round, types.VoteTypePrevote, hvs.valSet)
|
prevotes := NewVoteSet(hvs.height, round, types.VoteTypePrevote, hvs.valSet)
|
||||||
|
@ -146,7 +146,8 @@ func (hvs *HeightVoteSet) getVoteSet(round int, type_ byte) *VoteSet {
|
||||||
case types.VoteTypePrecommit:
|
case types.VoteTypePrecommit:
|
||||||
return rvs.Precommits
|
return rvs.Precommits
|
||||||
default:
|
default:
|
||||||
panic(Fmt("Unexpected vote type %X", type_))
|
PanicSanity(Fmt("Unexpected vote type %X", type_))
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -669,7 +669,7 @@ func (ps *PeerState) getVoteBitArray(height, round int, type_ byte) *BitArray {
|
||||||
case types.VoteTypePrecommit:
|
case types.VoteTypePrecommit:
|
||||||
return ps.Precommits
|
return ps.Precommits
|
||||||
default:
|
default:
|
||||||
panic(Fmt("Unexpected vote type %X", type_))
|
PanicSanity(Fmt("Unexpected vote type %X", type_))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ps.CatchupCommitRound == round {
|
if ps.CatchupCommitRound == round {
|
||||||
|
@ -679,7 +679,7 @@ func (ps *PeerState) getVoteBitArray(height, round int, type_ byte) *BitArray {
|
||||||
case types.VoteTypePrecommit:
|
case types.VoteTypePrecommit:
|
||||||
return ps.CatchupCommit
|
return ps.CatchupCommit
|
||||||
default:
|
default:
|
||||||
panic(Fmt("Unexpected vote type %X", type_))
|
PanicSanity(Fmt("Unexpected vote type %X", type_))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -692,7 +692,7 @@ func (ps *PeerState) getVoteBitArray(height, round int, type_ byte) *BitArray {
|
||||||
case types.VoteTypePrecommit:
|
case types.VoteTypePrecommit:
|
||||||
return ps.LastCommit
|
return ps.LastCommit
|
||||||
default:
|
default:
|
||||||
panic(Fmt("Unexpected vote type %X", type_))
|
PanicSanity(Fmt("Unexpected vote type %X", type_))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -706,7 +706,7 @@ func (ps *PeerState) ensureCatchupCommitRound(height, round int, numValidators i
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ps.CatchupCommitRound != -1 && ps.CatchupCommitRound != round {
|
if ps.CatchupCommitRound != -1 && ps.CatchupCommitRound != round {
|
||||||
panic(Fmt("Conflicting CatchupCommitRound. Height: %v, Orig: %v, New: %v", height, ps.CatchupCommitRound, round))
|
PanicSanity(Fmt("Conflicting CatchupCommitRound. Height: %v, Orig: %v, New: %v", height, ps.CatchupCommitRound, round))
|
||||||
}
|
}
|
||||||
if ps.CatchupCommitRound == round {
|
if ps.CatchupCommitRound == round {
|
||||||
return // Nothing to do!
|
return // Nothing to do!
|
||||||
|
@ -758,7 +758,7 @@ func (ps *PeerState) SetHasVote(vote *types.Vote, index int) {
|
||||||
func (ps *PeerState) setHasVote(height int, round int, type_ byte, index int) {
|
func (ps *PeerState) setHasVote(height int, round int, type_ byte, index int) {
|
||||||
log := log.New("peer", ps.Peer.Key, "peerRound", ps.Round, "height", height, "round", round)
|
log := log.New("peer", ps.Peer.Key, "peerRound", ps.Round, "height", height, "round", round)
|
||||||
if type_ != types.VoteTypePrevote && type_ != types.VoteTypePrecommit {
|
if type_ != types.VoteTypePrevote && type_ != types.VoteTypePrecommit {
|
||||||
panic("Invalid vote type") // SANITY
|
PanicSanity("Invalid vote type")
|
||||||
}
|
}
|
||||||
|
|
||||||
if ps.Height == height {
|
if ps.Height == height {
|
||||||
|
|
|
@ -330,11 +330,11 @@ func (cs *ConsensusState) reconstructLastCommit(state *sm.State) {
|
||||||
}
|
}
|
||||||
added, _, err := lastPrecommits.AddByIndex(idx, precommit)
|
added, _, err := lastPrecommits.AddByIndex(idx, precommit)
|
||||||
if !added || err != nil {
|
if !added || err != nil {
|
||||||
panic(Fmt("Failed to reconstruct LastCommit: %v", err))
|
PanicCrisis(Fmt("Failed to reconstruct LastCommit: %v", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !lastPrecommits.HasTwoThirdsMajority() {
|
if !lastPrecommits.HasTwoThirdsMajority() {
|
||||||
panic("Failed to reconstruct LastCommit: Does not have +2/3 maj")
|
PanicSanity("Failed to reconstruct LastCommit: Does not have +2/3 maj")
|
||||||
}
|
}
|
||||||
cs.LastCommit = lastPrecommits
|
cs.LastCommit = lastPrecommits
|
||||||
}
|
}
|
||||||
|
@ -383,18 +383,16 @@ func (cs *ConsensusState) scheduleRound0(height int) {
|
||||||
// Updates ConsensusState and increments height to match that of state.
|
// Updates ConsensusState and increments height to match that of state.
|
||||||
// The round becomes 0 and cs.Step becomes RoundStepNewHeight.
|
// The round becomes 0 and cs.Step becomes RoundStepNewHeight.
|
||||||
func (cs *ConsensusState) updateToState(state *sm.State, contiguous bool) {
|
func (cs *ConsensusState) updateToState(state *sm.State, contiguous bool) {
|
||||||
// SANITY CHECK
|
|
||||||
if contiguous && 0 < cs.Height && cs.Height != state.LastBlockHeight {
|
if contiguous && 0 < cs.Height && cs.Height != state.LastBlockHeight {
|
||||||
panic(Fmt("updateToState() expected state height of %v but found %v",
|
PanicSanity(Fmt("updateToState() expected state height of %v but found %v",
|
||||||
cs.Height, state.LastBlockHeight))
|
cs.Height, state.LastBlockHeight))
|
||||||
}
|
}
|
||||||
if cs.state != nil && cs.state.LastBlockHeight+1 != cs.Height {
|
if cs.state != nil && cs.state.LastBlockHeight+1 != cs.Height {
|
||||||
// This might happen when someone else is mutating cs.state.
|
// This might happen when someone else is mutating cs.state.
|
||||||
// Someone forgot to pass in state.Copy() somewhere?!
|
// Someone forgot to pass in state.Copy() somewhere?!
|
||||||
panic(Fmt("Inconsistent cs.state.LastBlockHeight+1 %v vs cs.Height %v",
|
PanicSanity(Fmt("Inconsistent cs.state.LastBlockHeight+1 %v vs cs.Height %v",
|
||||||
cs.state.LastBlockHeight+1, cs.Height))
|
cs.state.LastBlockHeight+1, cs.Height))
|
||||||
}
|
}
|
||||||
// END SANITY CHECK
|
|
||||||
|
|
||||||
// If state isn't further out than cs.state, just ignore.
|
// If state isn't further out than cs.state, just ignore.
|
||||||
// This happens when SwitchToConsensus() is called in the reactor.
|
// This happens when SwitchToConsensus() is called in the reactor.
|
||||||
|
@ -410,7 +408,7 @@ func (cs *ConsensusState) updateToState(state *sm.State, contiguous bool) {
|
||||||
lastPrecommits := (*VoteSet)(nil)
|
lastPrecommits := (*VoteSet)(nil)
|
||||||
if contiguous && cs.Votes != nil {
|
if contiguous && cs.Votes != nil {
|
||||||
if !cs.Votes.Precommits(cs.Round).HasTwoThirdsMajority() {
|
if !cs.Votes.Precommits(cs.Round).HasTwoThirdsMajority() {
|
||||||
panic("updateToState(state, true) called but last Precommit round didn't have +2/3")
|
PanicSanity("updateToState(state, true) called but last Precommit round didn't have +2/3")
|
||||||
}
|
}
|
||||||
lastPrecommits = cs.Votes.Precommits(cs.Round)
|
lastPrecommits = cs.Votes.Precommits(cs.Round)
|
||||||
}
|
}
|
||||||
|
@ -717,7 +715,7 @@ func (cs *ConsensusState) EnterPrevoteWait(height int, round int) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !cs.Votes.Prevotes(round).HasTwoThirdsAny() {
|
if !cs.Votes.Prevotes(round).HasTwoThirdsAny() {
|
||||||
panic(Fmt("EnterPrevoteWait(%v/%v), but Prevotes does not have any +2/3 votes", height, round))
|
PanicSanity(Fmt("EnterPrevoteWait(%v/%v), but Prevotes does not have any +2/3 votes", height, round))
|
||||||
}
|
}
|
||||||
log.Info(Fmt("EnterPrevoteWait(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step))
|
log.Info(Fmt("EnterPrevoteWait(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step))
|
||||||
|
|
||||||
|
@ -801,7 +799,7 @@ func (cs *ConsensusState) EnterPrecommit(height int, round int) {
|
||||||
log.Info("EnterPrecommit: +2/3 prevoted proposal block.")
|
log.Info("EnterPrecommit: +2/3 prevoted proposal block.")
|
||||||
// Validate the block.
|
// Validate the block.
|
||||||
if err := cs.stageBlock(cs.ProposalBlock, cs.ProposalBlockParts); err != nil {
|
if err := cs.stageBlock(cs.ProposalBlock, cs.ProposalBlockParts); err != nil {
|
||||||
panic(Fmt("EnterPrecommit: +2/3 prevoted for an invalid block: %v", err))
|
PanicConsensus(Fmt("EnterPrecommit: +2/3 prevoted for an invalid block: %v", err))
|
||||||
}
|
}
|
||||||
cs.LockedRound = round
|
cs.LockedRound = round
|
||||||
cs.LockedBlock = cs.ProposalBlock
|
cs.LockedBlock = cs.ProposalBlock
|
||||||
|
@ -814,7 +812,7 @@ func (cs *ConsensusState) EnterPrecommit(height int, round int) {
|
||||||
// Unlock and precommit nil.
|
// Unlock and precommit nil.
|
||||||
// The +2/3 prevotes for this round is the POL for our unlock.
|
// The +2/3 prevotes for this round is the POL for our unlock.
|
||||||
if cs.Votes.POLRound() < round {
|
if cs.Votes.POLRound() < round {
|
||||||
panic(Fmt("This POLRound shold be %v but got %", round, cs.Votes.POLRound()))
|
PanicSanity(Fmt("This POLRound shold be %v but got %", round, cs.Votes.POLRound()))
|
||||||
}
|
}
|
||||||
cs.LockedRound = 0
|
cs.LockedRound = 0
|
||||||
cs.LockedBlock = nil
|
cs.LockedBlock = nil
|
||||||
|
@ -836,7 +834,7 @@ func (cs *ConsensusState) EnterPrecommitWait(height int, round int) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !cs.Votes.Precommits(round).HasTwoThirdsAny() {
|
if !cs.Votes.Precommits(round).HasTwoThirdsAny() {
|
||||||
panic(Fmt("EnterPrecommitWait(%v/%v), but Precommits does not have any +2/3 votes", height, round))
|
PanicSanity(Fmt("EnterPrecommitWait(%v/%v), but Precommits does not have any +2/3 votes", height, round))
|
||||||
}
|
}
|
||||||
log.Info(Fmt("EnterPrecommitWait(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step))
|
log.Info(Fmt("EnterPrecommitWait(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step))
|
||||||
|
|
||||||
|
@ -876,12 +874,10 @@ func (cs *ConsensusState) EnterCommit(height int) {
|
||||||
cs.tryFinalizeCommit(height)
|
cs.tryFinalizeCommit(height)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// SANITY CHECK
|
|
||||||
hash, partsHeader, ok := cs.Votes.Precommits(cs.Round).TwoThirdsMajority()
|
hash, partsHeader, ok := cs.Votes.Precommits(cs.Round).TwoThirdsMajority()
|
||||||
if !ok {
|
if !ok {
|
||||||
panic("RunActionCommit() expects +2/3 precommits")
|
PanicSanity("RunActionCommit() expects +2/3 precommits")
|
||||||
}
|
}
|
||||||
// END SANITY CHECK
|
|
||||||
|
|
||||||
// The Locked* fields no longer matter.
|
// The Locked* fields no longer matter.
|
||||||
// Move them over to ProposalBlock if they match the commit hash,
|
// Move them over to ProposalBlock if they match the commit hash,
|
||||||
|
@ -913,11 +909,9 @@ func (cs *ConsensusState) EnterCommit(height int) {
|
||||||
|
|
||||||
// If we have the block AND +2/3 commits for it, finalize.
|
// If we have the block AND +2/3 commits for it, finalize.
|
||||||
func (cs *ConsensusState) tryFinalizeCommit(height int) {
|
func (cs *ConsensusState) tryFinalizeCommit(height int) {
|
||||||
// SANITY CHECK
|
|
||||||
if cs.Height != height {
|
if cs.Height != height {
|
||||||
panic(Fmt("tryFinalizeCommit() cs.Height: %v vs height: %v", cs.Height, height))
|
PanicSanity(Fmt("tryFinalizeCommit() cs.Height: %v vs height: %v", cs.Height, height))
|
||||||
}
|
}
|
||||||
// END SANITY CHECK
|
|
||||||
|
|
||||||
hash, _, ok := cs.Votes.Precommits(cs.Round).TwoThirdsMajority()
|
hash, _, ok := cs.Votes.Precommits(cs.Round).TwoThirdsMajority()
|
||||||
if !ok || len(hash) == 0 {
|
if !ok || len(hash) == 0 {
|
||||||
|
@ -941,20 +935,18 @@ func (cs *ConsensusState) FinalizeCommit(height int) {
|
||||||
|
|
||||||
hash, header, ok := cs.Votes.Precommits(cs.Round).TwoThirdsMajority()
|
hash, header, ok := cs.Votes.Precommits(cs.Round).TwoThirdsMajority()
|
||||||
|
|
||||||
// SANITY CHECK
|
|
||||||
if !ok {
|
if !ok {
|
||||||
panic(Fmt("Cannot FinalizeCommit, commit does not have two thirds majority"))
|
PanicSanity(Fmt("Cannot FinalizeCommit, commit does not have two thirds majority"))
|
||||||
}
|
}
|
||||||
if !cs.ProposalBlockParts.HasHeader(header) {
|
if !cs.ProposalBlockParts.HasHeader(header) {
|
||||||
panic(Fmt("Expected ProposalBlockParts header to be commit header"))
|
PanicSanity(Fmt("Expected ProposalBlockParts header to be commit header"))
|
||||||
}
|
}
|
||||||
if !cs.ProposalBlock.HashesTo(hash) {
|
if !cs.ProposalBlock.HashesTo(hash) {
|
||||||
panic(Fmt("Cannot FinalizeCommit, ProposalBlock does not hash to commit hash"))
|
PanicSanity(Fmt("Cannot FinalizeCommit, ProposalBlock does not hash to commit hash"))
|
||||||
}
|
}
|
||||||
if err := cs.stageBlock(cs.ProposalBlock, cs.ProposalBlockParts); err != nil {
|
if err := cs.stageBlock(cs.ProposalBlock, cs.ProposalBlockParts); err != nil {
|
||||||
panic(Fmt("+2/3 committed an invalid block: %v", err))
|
PanicConsensus(Fmt("+2/3 committed an invalid block: %v", err))
|
||||||
}
|
}
|
||||||
// END SANITY CHECK
|
|
||||||
|
|
||||||
log.Info(Fmt("Finalizing commit of block: %v", cs.ProposalBlock))
|
log.Info(Fmt("Finalizing commit of block: %v", cs.ProposalBlock))
|
||||||
// We have the block, so stage/save/commit-vote.
|
// We have the block, so stage/save/commit-vote.
|
||||||
|
@ -1132,7 +1124,7 @@ func (cs *ConsensusState) addVote(address []byte, vote *types.Vote, peerKey stri
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
panic(Fmt("Unexpected vote type %X", vote.Type)) // Should not happen.
|
PanicSanity(Fmt("Unexpected vote type %X", vote.Type)) // Should not happen.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Either duplicate, or error upon cs.Votes.AddByAddress()
|
// Either duplicate, or error upon cs.Votes.AddByAddress()
|
||||||
|
@ -1146,7 +1138,7 @@ func (cs *ConsensusState) addVote(address []byte, vote *types.Vote, peerKey stri
|
||||||
|
|
||||||
func (cs *ConsensusState) stageBlock(block *types.Block, blockParts *types.PartSet) error {
|
func (cs *ConsensusState) stageBlock(block *types.Block, blockParts *types.PartSet) error {
|
||||||
if block == nil {
|
if block == nil {
|
||||||
panic("Cannot stage nil block")
|
PanicSanity("Cannot stage nil block")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Already staged?
|
// Already staged?
|
||||||
|
@ -1200,7 +1192,7 @@ func (cs *ConsensusState) saveBlock(block *types.Block, blockParts *types.PartSe
|
||||||
|
|
||||||
// The proposal must be valid.
|
// The proposal must be valid.
|
||||||
if err := cs.stageBlock(block, blockParts); err != nil {
|
if err := cs.stageBlock(block, blockParts); err != nil {
|
||||||
panic(Fmt("saveBlock() an invalid block: %v", err))
|
PanicSanity(Fmt("saveBlock() an invalid block: %v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save to blockStore.
|
// Save to blockStore.
|
||||||
|
|
|
@ -37,7 +37,7 @@ type VoteSet struct {
|
||||||
// Constructs a new VoteSet struct used to accumulate votes for given height/round.
|
// Constructs a new VoteSet struct used to accumulate votes for given height/round.
|
||||||
func NewVoteSet(height int, round int, type_ byte, valSet *sm.ValidatorSet) *VoteSet {
|
func NewVoteSet(height int, round int, type_ byte, valSet *sm.ValidatorSet) *VoteSet {
|
||||||
if height == 0 {
|
if height == 0 {
|
||||||
panic("Cannot make VoteSet for height == 0, doesn't make sense.")
|
PanicSanity("Cannot make VoteSet for height == 0, doesn't make sense.")
|
||||||
}
|
}
|
||||||
return &VoteSet{
|
return &VoteSet{
|
||||||
height: height,
|
height: height,
|
||||||
|
@ -187,7 +187,7 @@ func (voteSet *VoteSet) GetByAddress(address []byte) *types.Vote {
|
||||||
defer voteSet.mtx.Unlock()
|
defer voteSet.mtx.Unlock()
|
||||||
valIndex, val := voteSet.valSet.GetByAddress(address)
|
valIndex, val := voteSet.valSet.GetByAddress(address)
|
||||||
if val == nil {
|
if val == nil {
|
||||||
panic("GetByAddress(address) returned nil")
|
PanicSanity("GetByAddress(address) returned nil")
|
||||||
}
|
}
|
||||||
return voteSet.votes[valIndex]
|
return voteSet.votes[valIndex]
|
||||||
}
|
}
|
||||||
|
@ -273,12 +273,12 @@ func (voteSet *VoteSet) StringShort() string {
|
||||||
|
|
||||||
func (voteSet *VoteSet) MakeValidation() *types.Validation {
|
func (voteSet *VoteSet) MakeValidation() *types.Validation {
|
||||||
if voteSet.type_ != types.VoteTypePrecommit {
|
if voteSet.type_ != types.VoteTypePrecommit {
|
||||||
panic("Cannot MakeValidation() unless VoteSet.Type is types.VoteTypePrecommit")
|
PanicSanity("Cannot MakeValidation() unless VoteSet.Type is types.VoteTypePrecommit")
|
||||||
}
|
}
|
||||||
voteSet.mtx.Lock()
|
voteSet.mtx.Lock()
|
||||||
defer voteSet.mtx.Unlock()
|
defer voteSet.mtx.Unlock()
|
||||||
if len(voteSet.maj23Hash) == 0 {
|
if len(voteSet.maj23Hash) == 0 {
|
||||||
panic("Cannot MakeValidation() unless a blockhash has +2/3")
|
PanicSanity("Cannot MakeValidation() unless a blockhash has +2/3")
|
||||||
}
|
}
|
||||||
precommits := make([]*types.Vote, voteSet.valSet.Size())
|
precommits := make([]*types.Vote, voteSet.valSet.Size())
|
||||||
voteSet.valSet.Iterate(func(valIndex int, val *sm.Validator) bool {
|
voteSet.valSet.Iterate(func(valIndex int, val *sm.Validator) bool {
|
||||||
|
|
5
db/db.go
5
db/db.go
|
@ -39,11 +39,12 @@ func GetDB(name string) DB {
|
||||||
case DBBackendLevelDB:
|
case DBBackendLevelDB:
|
||||||
db, err := NewLevelDB(path.Join(config.GetString("db_dir"), name+".db"))
|
db, err := NewLevelDB(path.Join(config.GetString("db_dir"), name+".db"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
PanicCrisis(err)
|
||||||
}
|
}
|
||||||
dbs.Set(name, db)
|
dbs.Set(name, db)
|
||||||
return db
|
return db
|
||||||
default:
|
default:
|
||||||
panic(Fmt("Unknown DB backend: %v", config.GetString("db_backend")))
|
PanicSanity(Fmt("Unknown DB backend: %v", config.GetString("db_backend")))
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@ import (
|
||||||
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/errors"
|
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/errors"
|
||||||
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/opt"
|
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/opt"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
|
. "github.com/tendermint/tendermint/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LevelDB struct {
|
type LevelDB struct {
|
||||||
|
@ -28,7 +30,7 @@ func (db *LevelDB) Get(key []byte) []byte {
|
||||||
if err == errors.ErrNotFound {
|
if err == errors.ErrNotFound {
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
panic(err)
|
PanicCrisis(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
|
@ -37,28 +39,28 @@ func (db *LevelDB) Get(key []byte) []byte {
|
||||||
func (db *LevelDB) Set(key []byte, value []byte) {
|
func (db *LevelDB) Set(key []byte, value []byte) {
|
||||||
err := db.db.Put(key, value, nil)
|
err := db.db.Put(key, value, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
PanicCrisis(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *LevelDB) SetSync(key []byte, value []byte) {
|
func (db *LevelDB) SetSync(key []byte, value []byte) {
|
||||||
err := db.db.Put(key, value, &opt.WriteOptions{Sync: true})
|
err := db.db.Put(key, value, &opt.WriteOptions{Sync: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
PanicCrisis(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *LevelDB) Delete(key []byte) {
|
func (db *LevelDB) Delete(key []byte) {
|
||||||
err := db.db.Delete(key, nil)
|
err := db.db.Delete(key, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
PanicCrisis(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *LevelDB) DeleteSync(key []byte) {
|
func (db *LevelDB) DeleteSync(key []byte) {
|
||||||
err := db.db.Delete(key, &opt.WriteOptions{Sync: true})
|
err := db.db.Delete(key, &opt.WriteOptions{Sync: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
PanicCrisis(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/binary"
|
||||||
|
. "github.com/tendermint/tendermint/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Node
|
// Node
|
||||||
|
@ -50,15 +51,12 @@ func ReadIAVLNode(t *IAVLTree, r io.Reader, n *int64, err *error) *IAVLNode {
|
||||||
node.leftHash = binary.ReadByteSlice(r, n, err)
|
node.leftHash = binary.ReadByteSlice(r, n, err)
|
||||||
node.rightHash = binary.ReadByteSlice(r, n, err)
|
node.rightHash = binary.ReadByteSlice(r, n, err)
|
||||||
}
|
}
|
||||||
if *err != nil {
|
|
||||||
panic(*err)
|
|
||||||
}
|
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
|
||||||
func (node *IAVLNode) _copy() *IAVLNode {
|
func (node *IAVLNode) _copy() *IAVLNode {
|
||||||
if node.height == 0 {
|
if node.height == 0 {
|
||||||
panic("Why are you copying a value node?")
|
PanicSanity("Why are you copying a value node?")
|
||||||
}
|
}
|
||||||
return &IAVLNode{
|
return &IAVLNode{
|
||||||
key: node.key,
|
key: node.key,
|
||||||
|
@ -112,7 +110,8 @@ func (node *IAVLNode) getByIndex(t *IAVLTree, index int) (key interface{}, value
|
||||||
if index == 0 {
|
if index == 0 {
|
||||||
return node.key, node.value
|
return node.key, node.value
|
||||||
} else {
|
} else {
|
||||||
panic("getByIndex asked for invalid index")
|
PanicSanity("getByIndex asked for invalid index")
|
||||||
|
return nil, nil
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO: could improve this by storing the
|
// TODO: could improve this by storing the
|
||||||
|
@ -136,7 +135,7 @@ func (node *IAVLNode) hashWithCount(t *IAVLTree) ([]byte, int) {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
_, hashCount, err := node.writeHashBytes(t, buf)
|
_, hashCount, err := node.writeHashBytes(t, buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
PanicCrisis(err)
|
||||||
}
|
}
|
||||||
// fmt.Printf("Wrote IAVL hash bytes: %X\n", buf.Bytes())
|
// fmt.Printf("Wrote IAVL hash bytes: %X\n", buf.Bytes())
|
||||||
hasher.Write(buf.Bytes())
|
hasher.Write(buf.Bytes())
|
||||||
|
@ -165,7 +164,7 @@ func (node *IAVLNode) writeHashBytes(t *IAVLTree, w io.Writer) (n int64, hashCou
|
||||||
hashCount += leftCount
|
hashCount += leftCount
|
||||||
}
|
}
|
||||||
if node.leftHash == nil {
|
if node.leftHash == nil {
|
||||||
panic("node.leftHash was nil in writeHashBytes")
|
PanicSanity("node.leftHash was nil in writeHashBytes")
|
||||||
}
|
}
|
||||||
binary.WriteByteSlice(node.leftHash, w, &n, &err)
|
binary.WriteByteSlice(node.leftHash, w, &n, &err)
|
||||||
// right
|
// right
|
||||||
|
@ -175,7 +174,7 @@ func (node *IAVLNode) writeHashBytes(t *IAVLTree, w io.Writer) (n int64, hashCou
|
||||||
hashCount += rightCount
|
hashCount += rightCount
|
||||||
}
|
}
|
||||||
if node.rightHash == nil {
|
if node.rightHash == nil {
|
||||||
panic("node.rightHash was nil in writeHashBytes")
|
PanicSanity("node.rightHash was nil in writeHashBytes")
|
||||||
}
|
}
|
||||||
binary.WriteByteSlice(node.rightHash, w, &n, &err)
|
binary.WriteByteSlice(node.rightHash, w, &n, &err)
|
||||||
}
|
}
|
||||||
|
@ -221,12 +220,12 @@ func (node *IAVLNode) writePersistBytes(t *IAVLTree, w io.Writer) (n int64, err
|
||||||
} else {
|
} else {
|
||||||
// left
|
// left
|
||||||
if node.leftHash == nil {
|
if node.leftHash == nil {
|
||||||
panic("node.leftHash was nil in writePersistBytes")
|
PanicSanity("node.leftHash was nil in writePersistBytes")
|
||||||
}
|
}
|
||||||
binary.WriteByteSlice(node.leftHash, w, &n, &err)
|
binary.WriteByteSlice(node.leftHash, w, &n, &err)
|
||||||
// right
|
// right
|
||||||
if node.rightHash == nil {
|
if node.rightHash == nil {
|
||||||
panic("node.rightHash was nil in writePersistBytes")
|
PanicSanity("node.rightHash was nil in writePersistBytes")
|
||||||
}
|
}
|
||||||
binary.WriteByteSlice(node.rightHash, w, &n, &err)
|
binary.WriteByteSlice(node.rightHash, w, &n, &err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ func (branch IAVLProofInnerNode) Hash(childHash []byte) []byte {
|
||||||
binary.WriteByteSlice(childHash, buf, &n, &err)
|
binary.WriteByteSlice(childHash, buf, &n, &err)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(Fmt("Failed to hash IAVLProofInnerNode: %v", err))
|
PanicCrisis(Fmt("Failed to hash IAVLProofInnerNode: %v", err))
|
||||||
}
|
}
|
||||||
// fmt.Printf("InnerNode hash bytes: %X\n", buf.Bytes())
|
// fmt.Printf("InnerNode hash bytes: %X\n", buf.Bytes())
|
||||||
hasher.Write(buf.Bytes())
|
hasher.Write(buf.Bytes())
|
||||||
|
@ -77,7 +77,7 @@ func (leaf IAVLProofLeafNode) Hash() []byte {
|
||||||
binary.WriteByteSlice(leaf.KeyBytes, buf, &n, &err)
|
binary.WriteByteSlice(leaf.KeyBytes, buf, &n, &err)
|
||||||
binary.WriteByteSlice(leaf.ValueBytes, buf, &n, &err)
|
binary.WriteByteSlice(leaf.ValueBytes, buf, &n, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(Fmt("Failed to hash IAVLProofLeafNode: %v", err))
|
PanicCrisis(Fmt("Failed to hash IAVLProofLeafNode: %v", err))
|
||||||
}
|
}
|
||||||
// fmt.Printf("LeafNode hash bytes: %X\n", buf.Bytes())
|
// fmt.Printf("LeafNode hash bytes: %X\n", buf.Bytes())
|
||||||
hasher.Write(buf.Bytes())
|
hasher.Write(buf.Bytes())
|
||||||
|
@ -91,11 +91,11 @@ func (node *IAVLNode) constructProof(t *IAVLTree, key interface{}, proof *IAVLPr
|
||||||
n, err := int64(0), error(nil)
|
n, err := int64(0), error(nil)
|
||||||
t.keyCodec.Encode(node.key, keyBuf, &n, &err)
|
t.keyCodec.Encode(node.key, keyBuf, &n, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(Fmt("Failed to encode node.key: %v", err))
|
PanicCrisis(Fmt("Failed to encode node.key: %v", err))
|
||||||
}
|
}
|
||||||
t.valueCodec.Encode(node.value, valueBuf, &n, &err)
|
t.valueCodec.Encode(node.value, valueBuf, &n, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(Fmt("Failed to encode node.value: %v", err))
|
PanicCrisis(Fmt("Failed to encode node.value: %v", err))
|
||||||
}
|
}
|
||||||
leaf := IAVLProofLeafNode{
|
leaf := IAVLProofLeafNode{
|
||||||
KeyBytes: keyBuf.Bytes(),
|
KeyBytes: keyBuf.Bytes(),
|
||||||
|
|
|
@ -54,7 +54,7 @@ func (t *IAVLTree) Copy() Tree {
|
||||||
// It sets all the hashes recursively,
|
// It sets all the hashes recursively,
|
||||||
// clears all the leftNode/rightNode values recursively,
|
// clears all the leftNode/rightNode values recursively,
|
||||||
// and all the .persisted flags get set.
|
// and all the .persisted flags get set.
|
||||||
panic("It is unsafe to Copy() an unpersisted tree.")
|
PanicSanity("It is unsafe to Copy() an unpersisted tree.")
|
||||||
} else if t.ndb == nil && t.root.hash == nil {
|
} else if t.ndb == nil && t.root.hash == nil {
|
||||||
// An in-memory IAVLTree is finalized when the hashes are
|
// An in-memory IAVLTree is finalized when the hashes are
|
||||||
// calculated.
|
// calculated.
|
||||||
|
@ -211,14 +211,14 @@ func (ndb *nodeDB) GetNode(t *IAVLTree, hash []byte) *IAVLNode {
|
||||||
buf := ndb.db.Get(hash)
|
buf := ndb.db.Get(hash)
|
||||||
if len(buf) == 0 {
|
if len(buf) == 0 {
|
||||||
ndb.db.(*dbm.LevelDB).Print()
|
ndb.db.(*dbm.LevelDB).Print()
|
||||||
panic(Fmt("Value missing for key %X", hash))
|
PanicSanity(Fmt("Value missing for key %X", hash))
|
||||||
}
|
}
|
||||||
r := bytes.NewReader(buf)
|
r := bytes.NewReader(buf)
|
||||||
var n int64
|
var n int64
|
||||||
var err error
|
var err error
|
||||||
node := ReadIAVLNode(t, r, &n, &err)
|
node := ReadIAVLNode(t, r, &n, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(Fmt("Error reading IAVLNode. bytes: %X error: %v", buf, err))
|
PanicCrisis(Fmt("Error reading IAVLNode. bytes: %X error: %v", buf, err))
|
||||||
}
|
}
|
||||||
node.hash = hash
|
node.hash = hash
|
||||||
node.persisted = true
|
node.persisted = true
|
||||||
|
@ -231,10 +231,10 @@ func (ndb *nodeDB) SaveNode(t *IAVLTree, node *IAVLNode) {
|
||||||
ndb.mtx.Lock()
|
ndb.mtx.Lock()
|
||||||
defer ndb.mtx.Unlock()
|
defer ndb.mtx.Unlock()
|
||||||
if node.hash == nil {
|
if node.hash == nil {
|
||||||
panic("Expected to find node.hash, but none found.")
|
PanicSanity("Expected to find node.hash, but none found.")
|
||||||
}
|
}
|
||||||
if node.persisted {
|
if node.persisted {
|
||||||
panic("Shouldn't be calling save on an already persisted node.")
|
PanicSanity("Shouldn't be calling save on an already persisted node.")
|
||||||
}
|
}
|
||||||
/*if _, ok := ndb.cache[string(node.hash)]; ok {
|
/*if _, ok := ndb.cache[string(node.hash)]; ok {
|
||||||
panic("Shouldn't be calling save on an already cached node.")
|
panic("Shouldn't be calling save on an already cached node.")
|
||||||
|
@ -243,7 +243,7 @@ func (ndb *nodeDB) SaveNode(t *IAVLTree, node *IAVLNode) {
|
||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
_, err := node.writePersistBytes(t, buf)
|
_, err := node.writePersistBytes(t, buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
PanicCrisis(err)
|
||||||
}
|
}
|
||||||
ndb.db.Set(node.hash, buf.Bytes())
|
ndb.db.Set(node.hash, buf.Bytes())
|
||||||
node.persisted = true
|
node.persisted = true
|
||||||
|
|
|
@ -31,6 +31,7 @@ import (
|
||||||
"github.com/tendermint/tendermint/Godeps/_workspace/src/code.google.com/p/go.crypto/ripemd160"
|
"github.com/tendermint/tendermint/Godeps/_workspace/src/code.google.com/p/go.crypto/ripemd160"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/binary"
|
||||||
|
. "github.com/tendermint/tendermint/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SimpleHashFromTwoHashes(left []byte, right []byte) []byte {
|
func SimpleHashFromTwoHashes(left []byte, right []byte) []byte {
|
||||||
|
@ -40,7 +41,7 @@ func SimpleHashFromTwoHashes(left []byte, right []byte) []byte {
|
||||||
binary.WriteByteSlice(left, hasher, &n, &err)
|
binary.WriteByteSlice(left, hasher, &n, &err)
|
||||||
binary.WriteByteSlice(right, hasher, &n, &err)
|
binary.WriteByteSlice(right, hasher, &n, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
PanicCrisis(err)
|
||||||
}
|
}
|
||||||
return hasher.Sum(nil)
|
return hasher.Sum(nil)
|
||||||
}
|
}
|
||||||
|
@ -73,7 +74,7 @@ func SimpleHashFromBinary(item interface{}) []byte {
|
||||||
hasher, n, err := ripemd160.New(), new(int64), new(error)
|
hasher, n, err := ripemd160.New(), new(int64), new(error)
|
||||||
binary.WriteBinary(item, hasher, n, err)
|
binary.WriteBinary(item, hasher, n, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
panic(err)
|
PanicCrisis(err)
|
||||||
}
|
}
|
||||||
return hasher.Sum(nil)
|
return hasher.Sum(nil)
|
||||||
}
|
}
|
||||||
|
@ -162,7 +163,8 @@ func computeHashFromInnerHashes(index int, total int, leafHash []byte, innerHash
|
||||||
}
|
}
|
||||||
switch total {
|
switch total {
|
||||||
case 0:
|
case 0:
|
||||||
panic("Cannot call computeHashFromInnerHashes() with 0 total")
|
PanicSanity("Cannot call computeHashFromInnerHashes() with 0 total")
|
||||||
|
return nil
|
||||||
case 1:
|
case 1:
|
||||||
if len(innerHashes) != 0 {
|
if len(innerHashes) != 0 {
|
||||||
return nil
|
return nil
|
||||||
|
|
21
node/node.go
21
node/node.go
|
@ -66,14 +66,16 @@ func NewNode() *Node {
|
||||||
binary.WriteJSON(genDoc, buf, n, err)
|
binary.WriteJSON(genDoc, buf, n, err)
|
||||||
stateDB.Set(sm.GenDocKey, buf.Bytes())
|
stateDB.Set(sm.GenDocKey, buf.Bytes())
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
panic(Fmt("Unable to write gendoc to db: %v", err))
|
log.Error("Unable to write gendoc to db", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
genDocBytes := stateDB.Get(sm.GenDocKey)
|
genDocBytes := stateDB.Get(sm.GenDocKey)
|
||||||
err := new(error)
|
err := new(error)
|
||||||
binary.ReadJSONPtr(&genDoc, genDocBytes, err)
|
binary.ReadJSONPtr(&genDoc, genDocBytes, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
panic(Fmt("Unable to read gendoc from db: %v", err))
|
log.Error("Unable to read gendoc from db", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// add the chainid to the global config
|
// add the chainid to the global config
|
||||||
|
@ -204,7 +206,7 @@ func (n *Node) dialSeed(addr *p2p.NetAddress) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) StartRPC() net.Listener {
|
func (n *Node) StartRPC() (net.Listener, error) {
|
||||||
core.SetBlockStore(n.blockStore)
|
core.SetBlockStore(n.blockStore)
|
||||||
core.SetConsensusState(n.consensusState)
|
core.SetConsensusState(n.consensusState)
|
||||||
core.SetConsensusReactor(n.consensusReactor)
|
core.SetConsensusReactor(n.consensusReactor)
|
||||||
|
@ -217,11 +219,7 @@ func (n *Node) StartRPC() net.Listener {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
rpcserver.RegisterEventsHandler(mux, n.evsw)
|
rpcserver.RegisterEventsHandler(mux, n.evsw)
|
||||||
rpcserver.RegisterRPCFuncs(mux, core.Routes)
|
rpcserver.RegisterRPCFuncs(mux, core.Routes)
|
||||||
listener, err := rpcserver.StartHTTPServer(listenAddr, mux)
|
return rpcserver.StartHTTPServer(listenAddr, mux)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return listener
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) Switch() *p2p.Switch {
|
func (n *Node) Switch() *p2p.Switch {
|
||||||
|
@ -269,7 +267,7 @@ func makeNodeInfo(sw *p2p.Switch, privKey acm.PrivKeyEd25519) *types.NodeInfo {
|
||||||
_, rpcPortStr, _ := net.SplitHostPort(rpcListenAddr)
|
_, rpcPortStr, _ := net.SplitHostPort(rpcListenAddr)
|
||||||
rpcPort, err := strconv.Atoi(rpcPortStr)
|
rpcPort, err := strconv.Atoi(rpcPortStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(Fmt("Expected numeric RPC.ListenAddr port but got %v", rpcPortStr))
|
PanicSanity(Fmt("Expected numeric RPC.ListenAddr port but got %v", rpcPortStr))
|
||||||
}
|
}
|
||||||
|
|
||||||
// We assume that the rpcListener has the same ExternalAddress.
|
// We assume that the rpcListener has the same ExternalAddress.
|
||||||
|
@ -299,7 +297,10 @@ func RunNode() {
|
||||||
|
|
||||||
// Run the RPC server.
|
// Run the RPC server.
|
||||||
if config.GetString("rpc_laddr") != "" {
|
if config.GetString("rpc_laddr") != "" {
|
||||||
n.StartRPC()
|
_, err := n.StartRPC()
|
||||||
|
if err != nil {
|
||||||
|
PanicCrisis(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sleep forever and then...
|
// Sleep forever and then...
|
||||||
|
|
|
@ -200,7 +200,7 @@ func (a *AddrBook) PickAddress(newBias int) *NetAddress {
|
||||||
}
|
}
|
||||||
randIndex--
|
randIndex--
|
||||||
}
|
}
|
||||||
panic("Should not happen")
|
PanicSanity("Should not happen")
|
||||||
} else {
|
} else {
|
||||||
// pick random New bucket.
|
// pick random New bucket.
|
||||||
var bucket map[string]*knownAddress = nil
|
var bucket map[string]*knownAddress = nil
|
||||||
|
@ -215,7 +215,7 @@ func (a *AddrBook) PickAddress(newBias int) *NetAddress {
|
||||||
}
|
}
|
||||||
randIndex--
|
randIndex--
|
||||||
}
|
}
|
||||||
panic("Should not happen")
|
PanicSanity("Should not happen")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -332,14 +332,14 @@ func (a *AddrBook) loadFromFile(filePath string) bool {
|
||||||
// Load addrBookJSON{}
|
// Load addrBookJSON{}
|
||||||
r, err := os.Open(filePath)
|
r, err := os.Open(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(Fmt("Error opening file %s: %v", filePath, err))
|
PanicCrisis(Fmt("Error opening file %s: %v", filePath, err))
|
||||||
}
|
}
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
aJSON := &addrBookJSON{}
|
aJSON := &addrBookJSON{}
|
||||||
dec := json.NewDecoder(r)
|
dec := json.NewDecoder(r)
|
||||||
err = dec.Decode(aJSON)
|
err = dec.Decode(aJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(Fmt("Error reading file %s: %v", filePath, err))
|
PanicCrisis(Fmt("Error reading file %s: %v", filePath, err))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore all the fields...
|
// Restore all the fields...
|
||||||
|
@ -388,7 +388,8 @@ func (a *AddrBook) getBucket(bucketType byte, bucketIdx int) map[string]*knownAd
|
||||||
case bucketTypeOld:
|
case bucketTypeOld:
|
||||||
return a.addrOld[bucketIdx]
|
return a.addrOld[bucketIdx]
|
||||||
default:
|
default:
|
||||||
panic("Should not happen")
|
PanicSanity("Should not happen")
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -420,7 +420,7 @@ FOR_LOOP:
|
||||||
}
|
}
|
||||||
channel, ok := c.channelsIdx[pkt.ChannelId]
|
channel, ok := c.channelsIdx[pkt.ChannelId]
|
||||||
if !ok || channel == nil {
|
if !ok || channel == nil {
|
||||||
panic(Fmt("Unknown channel %X", pkt.ChannelId))
|
PanicQ(Fmt("Unknown channel %X", pkt.ChannelId))
|
||||||
}
|
}
|
||||||
msgBytes, err := channel.recvMsgPacket(pkt)
|
msgBytes, err := channel.recvMsgPacket(pkt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -435,7 +435,7 @@ FOR_LOOP:
|
||||||
c.onReceive(pkt.ChannelId, msgBytes)
|
c.onReceive(pkt.ChannelId, msgBytes)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
panic(Fmt("Unknown message type %X", pktType))
|
PanicSanity(Fmt("Unknown message type %X", pktType))
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: shouldn't this go in the sendRoutine?
|
// TODO: shouldn't this go in the sendRoutine?
|
||||||
|
@ -485,7 +485,7 @@ type Channel struct {
|
||||||
func newChannel(conn *MConnection, desc *ChannelDescriptor) *Channel {
|
func newChannel(conn *MConnection, desc *ChannelDescriptor) *Channel {
|
||||||
desc.FillDefaults()
|
desc.FillDefaults()
|
||||||
if desc.Priority <= 0 {
|
if desc.Priority <= 0 {
|
||||||
panic("Channel default priority must be a postive integer")
|
PanicSanity("Channel default priority must be a postive integer")
|
||||||
}
|
}
|
||||||
return &Channel{
|
return &Channel{
|
||||||
conn: conn,
|
conn: conn,
|
||||||
|
|
|
@ -35,11 +35,11 @@ const (
|
||||||
func splitHostPort(addr string) (host string, port int) {
|
func splitHostPort(addr string) (host string, port int) {
|
||||||
host, portStr, err := net.SplitHostPort(addr)
|
host, portStr, err := net.SplitHostPort(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
PanicSanity(err)
|
||||||
}
|
}
|
||||||
port, err = strconv.Atoi(portStr)
|
port, err = strconv.Atoi(portStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
PanicSanity(err)
|
||||||
}
|
}
|
||||||
return host, port
|
return host, port
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ func NewDefaultListener(protocol string, lAddr string, requireUPNPHairpin bool)
|
||||||
// Create listener
|
// Create listener
|
||||||
listener, err := net.Listen(protocol, lAddr)
|
listener, err := net.Listen(protocol, lAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
PanicCrisis(err)
|
||||||
}
|
}
|
||||||
// Actual listener local IP & port
|
// Actual listener local IP & port
|
||||||
listenerIP, listenerPort := splitHostPort(listener.Addr().String())
|
listenerIP, listenerPort := splitHostPort(listener.Addr().String())
|
||||||
|
@ -83,7 +83,7 @@ SKIP_UPNP:
|
||||||
extAddr = getNaiveExternalAddress(listenerPort)
|
extAddr = getNaiveExternalAddress(listenerPort)
|
||||||
}
|
}
|
||||||
if extAddr == nil {
|
if extAddr == nil {
|
||||||
panic("Could not determine external address!")
|
PanicCrisis("Could not determine external address!")
|
||||||
}
|
}
|
||||||
|
|
||||||
dl := &DefaultListener{
|
dl := &DefaultListener{
|
||||||
|
@ -117,7 +117,7 @@ func (l *DefaultListener) listenRoutine() {
|
||||||
// listener wasn't stopped,
|
// listener wasn't stopped,
|
||||||
// yet we encountered an error.
|
// yet we encountered an error.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
PanicCrisis(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
l.connections <- conn
|
l.connections <- conn
|
||||||
|
@ -190,7 +190,7 @@ func getUPNPExternalAddress(externalPort, internalPort int) *NetAddress {
|
||||||
func getNaiveExternalAddress(port int) *NetAddress {
|
func getNaiveExternalAddress(port int) *NetAddress {
|
||||||
addrs, err := net.InterfaceAddrs()
|
addrs, err := net.InterfaceAddrs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(Fmt("Could not fetch interface addresses: %v", err))
|
PanicCrisis(Fmt("Could not fetch interface addresses: %v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, a := range addrs {
|
for _, a := range addrs {
|
||||||
|
|
|
@ -9,6 +9,8 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
. "github.com/tendermint/tendermint/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NetAddress struct {
|
type NetAddress struct {
|
||||||
|
@ -21,7 +23,7 @@ type NetAddress struct {
|
||||||
func NewNetAddress(addr net.Addr) *NetAddress {
|
func NewNetAddress(addr net.Addr) *NetAddress {
|
||||||
tcpAddr, ok := addr.(*net.TCPAddr)
|
tcpAddr, ok := addr.(*net.TCPAddr)
|
||||||
if !ok {
|
if !ok {
|
||||||
panic(fmt.Sprintf("Only TCPAddrs are supported. Got: %v", addr))
|
PanicSanity(fmt.Sprintf("Only TCPAddrs are supported. Got: %v", addr))
|
||||||
}
|
}
|
||||||
ip := tcpAddr.IP
|
ip := tcpAddr.IP
|
||||||
port := uint16(tcpAddr.Port)
|
port := uint16(tcpAddr.Port)
|
||||||
|
@ -32,21 +34,21 @@ func NewNetAddress(addr net.Addr) *NetAddress {
|
||||||
func NewNetAddressString(addr string) *NetAddress {
|
func NewNetAddressString(addr string) *NetAddress {
|
||||||
host, portStr, err := net.SplitHostPort(addr)
|
host, portStr, err := net.SplitHostPort(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
PanicSanity(err)
|
||||||
}
|
}
|
||||||
ip := net.ParseIP(host)
|
ip := net.ParseIP(host)
|
||||||
if ip == nil {
|
if ip == nil {
|
||||||
if len(host) > 0 {
|
if len(host) > 0 {
|
||||||
ips, err := net.LookupIP(host)
|
ips, err := net.LookupIP(host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
PanicSanity(err)
|
||||||
}
|
}
|
||||||
ip = ips[0]
|
ip = ips[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
port, err := strconv.ParseUint(portStr, 10, 16)
|
port, err := strconv.ParseUint(portStr, 10, 16)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
PanicSanity(err)
|
||||||
}
|
}
|
||||||
na := NewNetAddressIPPort(ip, uint16(port))
|
na := NewNetAddressIPPort(ip, uint16(port))
|
||||||
return na
|
return na
|
||||||
|
@ -76,7 +78,8 @@ func (na *NetAddress) Less(other interface{}) bool {
|
||||||
if o, ok := other.(*NetAddress); ok {
|
if o, ok := other.(*NetAddress); ok {
|
||||||
return na.String() < o.String()
|
return na.String() < o.String()
|
||||||
} else {
|
} else {
|
||||||
panic("Cannot compare unequal types")
|
PanicSanity("Cannot compare unequal types")
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ func newPeer(conn net.Conn, peerNodeInfo *types.NodeInfo, outbound bool, reactor
|
||||||
onReceive := func(chId byte, msgBytes []byte) {
|
onReceive := func(chId byte, msgBytes []byte) {
|
||||||
reactor := reactorsByCh[chId]
|
reactor := reactorsByCh[chId]
|
||||||
if reactor == nil {
|
if reactor == nil {
|
||||||
panic(Fmt("Unknown channel %X", chId))
|
PanicSanity(Fmt("Unknown channel %X", chId))
|
||||||
}
|
}
|
||||||
reactor.Receive(chId, p, msgBytes)
|
reactor.Receive(chId, p, msgBytes)
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,7 +190,7 @@ func genEphKeys() (ephPub, ephPriv *[32]byte) {
|
||||||
var err error
|
var err error
|
||||||
ephPub, ephPriv, err = box.GenerateKey(crand.Reader)
|
ephPub, ephPriv, err = box.GenerateKey(crand.Reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("Could not generate ephemeral keypairs")
|
PanicCrisis("Could not generate ephemeral keypairs")
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ func (sw *Switch) AddReactor(name string, reactor Reactor) Reactor {
|
||||||
for _, chDesc := range reactorChannels {
|
for _, chDesc := range reactorChannels {
|
||||||
chId := chDesc.Id
|
chId := chDesc.Id
|
||||||
if sw.reactorsByCh[chId] != nil {
|
if sw.reactorsByCh[chId] != nil {
|
||||||
panic(fmt.Sprintf("Channel %X has multiple reactors %v & %v", chId, sw.reactorsByCh[chId], reactor))
|
PanicSanity(fmt.Sprintf("Channel %X has multiple reactors %v & %v", chId, sw.reactorsByCh[chId], reactor))
|
||||||
}
|
}
|
||||||
sw.chDescs = append(sw.chDescs, chDesc)
|
sw.chDescs = append(sw.chDescs, chDesc)
|
||||||
sw.reactorsByCh[chId] = reactor
|
sw.reactorsByCh[chId] = reactor
|
||||||
|
|
|
@ -6,8 +6,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
. "github.com/tendermint/tendermint/rpc/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -24,10 +22,6 @@ var (
|
||||||
//RE_ID12 = regexp.MustCompile(`^[a-zA-Z0-9]{12}$`)
|
//RE_ID12 = regexp.MustCompile(`^[a-zA-Z0-9]{12}$`)
|
||||||
)
|
)
|
||||||
|
|
||||||
func panicRPC(err error) {
|
|
||||||
panic(NewRPCResponse(nil, err.Error()))
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetParam(r *http.Request, param string) string {
|
func GetParam(r *http.Request, param string) string {
|
||||||
s := r.URL.Query().Get(param)
|
s := r.URL.Query().Get(param)
|
||||||
if s == "" {
|
if s == "" {
|
||||||
|
|
|
@ -64,21 +64,17 @@ func (cache *BlockCache) GetAccount(addr []byte) *acm.Account {
|
||||||
func (cache *BlockCache) UpdateAccount(acc *acm.Account) {
|
func (cache *BlockCache) UpdateAccount(acc *acm.Account) {
|
||||||
addr := acc.Address
|
addr := acc.Address
|
||||||
_, storage, removed, _ := cache.accounts[string(addr)].unpack()
|
_, storage, removed, _ := cache.accounts[string(addr)].unpack()
|
||||||
// SANITY CHECK
|
|
||||||
if removed {
|
if removed {
|
||||||
panic("UpdateAccount on a removed account")
|
PanicSanity("UpdateAccount on a removed account")
|
||||||
}
|
}
|
||||||
// SANITY CHECK END
|
|
||||||
cache.accounts[string(addr)] = accountInfo{acc, storage, false, true}
|
cache.accounts[string(addr)] = accountInfo{acc, storage, false, true}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cache *BlockCache) RemoveAccount(addr []byte) {
|
func (cache *BlockCache) RemoveAccount(addr []byte) {
|
||||||
// SANITY CHECK
|
|
||||||
_, _, removed, _ := cache.accounts[string(addr)].unpack()
|
_, _, removed, _ := cache.accounts[string(addr)].unpack()
|
||||||
if removed {
|
if removed {
|
||||||
panic("RemoveAccount on a removed account")
|
PanicSanity("RemoveAccount on a removed account")
|
||||||
}
|
}
|
||||||
// SANITY CHECK END
|
|
||||||
cache.accounts[string(addr)] = accountInfo{nil, nil, true, false}
|
cache.accounts[string(addr)] = accountInfo{nil, nil, true, false}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,11 +91,9 @@ func (cache *BlockCache) GetStorage(addr Word256, key Word256) (value Word256) {
|
||||||
|
|
||||||
// Get or load storage
|
// Get or load storage
|
||||||
acc, storage, removed, dirty := cache.accounts[string(addr.Postfix(20))].unpack()
|
acc, storage, removed, dirty := cache.accounts[string(addr.Postfix(20))].unpack()
|
||||||
// SANITY CHECK
|
|
||||||
if removed {
|
if removed {
|
||||||
panic("GetStorage() on removed account")
|
PanicSanity("GetStorage() on removed account")
|
||||||
}
|
}
|
||||||
// SANITY CHECK END
|
|
||||||
if acc != nil && storage == nil {
|
if acc != nil && storage == nil {
|
||||||
storage = makeStorage(cache.db, acc.StorageRoot)
|
storage = makeStorage(cache.db, acc.StorageRoot)
|
||||||
cache.accounts[string(addr.Postfix(20))] = accountInfo{acc, storage, false, dirty}
|
cache.accounts[string(addr.Postfix(20))] = accountInfo{acc, storage, false, dirty}
|
||||||
|
@ -119,12 +113,10 @@ func (cache *BlockCache) GetStorage(addr Word256, key Word256) (value Word256) {
|
||||||
|
|
||||||
// NOTE: Set value to zero to removed from the trie.
|
// NOTE: Set value to zero to removed from the trie.
|
||||||
func (cache *BlockCache) SetStorage(addr Word256, key Word256, value Word256) {
|
func (cache *BlockCache) SetStorage(addr Word256, key Word256, value Word256) {
|
||||||
// SANITY CHECK
|
|
||||||
_, _, removed, _ := cache.accounts[string(addr.Postfix(20))].unpack()
|
_, _, removed, _ := cache.accounts[string(addr.Postfix(20))].unpack()
|
||||||
if removed {
|
if removed {
|
||||||
panic("SetStorage() on a removed account")
|
PanicSanity("SetStorage() on a removed account")
|
||||||
}
|
}
|
||||||
// SANITY CHECK END
|
|
||||||
cache.storages[Tuple256{addr, key}] = storageInfo{value, true}
|
cache.storages[Tuple256{addr, key}] = storageInfo{value, true}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,12 +143,10 @@ func (cache *BlockCache) UpdateNameRegEntry(entry *types.NameRegEntry) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cache *BlockCache) RemoveNameRegEntry(name string) {
|
func (cache *BlockCache) RemoveNameRegEntry(name string) {
|
||||||
// SANITY CHECK
|
|
||||||
_, removed, _ := cache.names[name].unpack()
|
_, removed, _ := cache.names[name].unpack()
|
||||||
if removed {
|
if removed {
|
||||||
panic("RemoveNameRegEntry on a removed entry")
|
PanicSanity("RemoveNameRegEntry on a removed entry")
|
||||||
}
|
}
|
||||||
// SANITY CHECK END
|
|
||||||
cache.names[name] = nameInfo{nil, true, false}
|
cache.names[name] = nameInfo{nil, true, false}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,8 +212,7 @@ func (cache *BlockCache) Sync() {
|
||||||
if removed {
|
if removed {
|
||||||
removed := cache.backend.RemoveAccount(acc.Address)
|
removed := cache.backend.RemoveAccount(acc.Address)
|
||||||
if !removed {
|
if !removed {
|
||||||
// SOMETHING HORRIBLE HAS GONE WRONG
|
PanicCrisis(Fmt("Could not remove account to be removed: %X", acc.Address))
|
||||||
panic(Fmt("Could not remove account to be removed: %X", acc.Address))
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if acc == nil {
|
if acc == nil {
|
||||||
|
@ -256,8 +245,7 @@ func (cache *BlockCache) Sync() {
|
||||||
if removed {
|
if removed {
|
||||||
removed := cache.backend.RemoveNameRegEntry(nameStr)
|
removed := cache.backend.RemoveNameRegEntry(nameStr)
|
||||||
if !removed {
|
if !removed {
|
||||||
// SOMETHING HORRIBLE HAS GONE WRONG
|
PanicCrisis(Fmt("Could not remove namereg entry to be removed: %s", nameStr))
|
||||||
panic(Fmt("Could not remove namereg entry to be removed: %s", nameStr))
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if entry == nil {
|
if entry == nil {
|
||||||
|
|
|
@ -57,29 +57,28 @@ func execBlock(s *State, block *types.Block, blockPartsHeader types.PartSetHeade
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update Validator.LastCommitHeight as necessary.
|
// Update Validator.LastCommitHeight as necessary.
|
||||||
// If we panic in here, something has gone horribly wrong
|
|
||||||
for i, precommit := range block.LastValidation.Precommits {
|
for i, precommit := range block.LastValidation.Precommits {
|
||||||
if precommit == nil {
|
if precommit == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
_, val := s.LastBondedValidators.GetByIndex(i)
|
_, val := s.LastBondedValidators.GetByIndex(i)
|
||||||
if val == nil {
|
if val == nil {
|
||||||
panic(Fmt("Failed to fetch validator at index %v", i))
|
PanicCrisis(Fmt("Failed to fetch validator at index %v", i))
|
||||||
}
|
}
|
||||||
if _, val_ := s.BondedValidators.GetByAddress(val.Address); val_ != nil {
|
if _, val_ := s.BondedValidators.GetByAddress(val.Address); val_ != nil {
|
||||||
val_.LastCommitHeight = block.Height - 1
|
val_.LastCommitHeight = block.Height - 1
|
||||||
updated := s.BondedValidators.Update(val_)
|
updated := s.BondedValidators.Update(val_)
|
||||||
if !updated {
|
if !updated {
|
||||||
panic("Failed to update bonded validator LastCommitHeight")
|
PanicCrisis("Failed to update bonded validator LastCommitHeight")
|
||||||
}
|
}
|
||||||
} else if _, val_ := s.UnbondingValidators.GetByAddress(val.Address); val_ != nil {
|
} else if _, val_ := s.UnbondingValidators.GetByAddress(val.Address); val_ != nil {
|
||||||
val_.LastCommitHeight = block.Height - 1
|
val_.LastCommitHeight = block.Height - 1
|
||||||
updated := s.UnbondingValidators.Update(val_)
|
updated := s.UnbondingValidators.Update(val_)
|
||||||
if !updated {
|
if !updated {
|
||||||
panic("Failed to update unbonding validator LastCommitHeight")
|
PanicCrisis("Failed to update unbonding validator LastCommitHeight")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
panic("Could not find validator")
|
PanicCrisis("Could not find validator")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,11 +212,9 @@ func checkInputPubKey(acc *acm.Account, in *types.TxInput) error {
|
||||||
func validateInputs(accounts map[string]*acm.Account, signBytes []byte, ins []*types.TxInput) (total int64, err error) {
|
func validateInputs(accounts map[string]*acm.Account, signBytes []byte, ins []*types.TxInput) (total int64, err error) {
|
||||||
for _, in := range ins {
|
for _, in := range ins {
|
||||||
acc := accounts[string(in.Address)]
|
acc := accounts[string(in.Address)]
|
||||||
// SANITY CHECK
|
|
||||||
if acc == nil {
|
if acc == nil {
|
||||||
panic("validateInputs() expects account in accounts")
|
PanicSanity("validateInputs() expects account in accounts")
|
||||||
}
|
}
|
||||||
// SANITY CHECK END
|
|
||||||
err = validateInput(acc, signBytes, in)
|
err = validateInput(acc, signBytes, in)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -266,14 +263,12 @@ func validateOutputs(outs []*types.TxOutput) (total int64, err error) {
|
||||||
func adjustByInputs(accounts map[string]*acm.Account, ins []*types.TxInput) {
|
func adjustByInputs(accounts map[string]*acm.Account, ins []*types.TxInput) {
|
||||||
for _, in := range ins {
|
for _, in := range ins {
|
||||||
acc := accounts[string(in.Address)]
|
acc := accounts[string(in.Address)]
|
||||||
// SANITY CHECK
|
|
||||||
if acc == nil {
|
if acc == nil {
|
||||||
panic("adjustByInputs() expects account in accounts")
|
PanicSanity("adjustByInputs() expects account in accounts")
|
||||||
}
|
}
|
||||||
if acc.Balance < in.Amount {
|
if acc.Balance < in.Amount {
|
||||||
panic("adjustByInputs() expects sufficient funds")
|
PanicSanity("adjustByInputs() expects sufficient funds")
|
||||||
}
|
}
|
||||||
// SANITY CHECK END
|
|
||||||
acc.Balance -= in.Amount
|
acc.Balance -= in.Amount
|
||||||
acc.Sequence += 1
|
acc.Sequence += 1
|
||||||
}
|
}
|
||||||
|
@ -282,11 +277,9 @@ func adjustByInputs(accounts map[string]*acm.Account, ins []*types.TxInput) {
|
||||||
func adjustByOutputs(accounts map[string]*acm.Account, outs []*types.TxOutput) {
|
func adjustByOutputs(accounts map[string]*acm.Account, outs []*types.TxOutput) {
|
||||||
for _, out := range outs {
|
for _, out := range outs {
|
||||||
acc := accounts[string(out.Address)]
|
acc := accounts[string(out.Address)]
|
||||||
// SANITY CHECK
|
|
||||||
if acc == nil {
|
if acc == nil {
|
||||||
panic("adjustByOutputs() expects account in accounts")
|
PanicSanity("adjustByOutputs() expects account in accounts")
|
||||||
}
|
}
|
||||||
// SANITY CHECK END
|
|
||||||
acc.Balance += out.Amount
|
acc.Balance += out.Amount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -701,8 +694,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
|
||||||
Accum: 0,
|
Accum: 0,
|
||||||
})
|
})
|
||||||
if !added {
|
if !added {
|
||||||
// SOMETHING HAS GONE HORRIBLY WRONG
|
PanicCrisis("Failed to add validator")
|
||||||
panic("Failed to add validator")
|
|
||||||
}
|
}
|
||||||
if evc != nil {
|
if evc != nil {
|
||||||
evc.FireEvent(types.EventStringBond(), tx)
|
evc.FireEvent(types.EventStringBond(), tx)
|
||||||
|
@ -802,9 +794,9 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// SANITY CHECK (binary decoding should catch bad tx types
|
// binary decoding should not let this happen
|
||||||
// before they get here
|
PanicSanity("Unknown Tx type")
|
||||||
panic("Unknown Tx type")
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -813,7 +805,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
|
||||||
// Get permission on an account or fall back to global value
|
// Get permission on an account or fall back to global value
|
||||||
func HasPermission(state AccountGetter, acc *acm.Account, perm ptypes.PermFlag) bool {
|
func HasPermission(state AccountGetter, acc *acm.Account, perm ptypes.PermFlag) bool {
|
||||||
if perm > ptypes.AllBasePermFlags {
|
if perm > ptypes.AllBasePermFlags {
|
||||||
panic("Checking an unknown permission in state should never happen")
|
PanicSanity("Checking an unknown permission in state should never happen")
|
||||||
}
|
}
|
||||||
|
|
||||||
if acc == nil {
|
if acc == nil {
|
||||||
|
@ -826,7 +818,7 @@ func HasPermission(state AccountGetter, acc *acm.Account, perm ptypes.PermFlag)
|
||||||
if _, ok := err.(ptypes.ErrValueNotSet); ok {
|
if _, ok := err.(ptypes.ErrValueNotSet); ok {
|
||||||
log.Info("Account does not have permission", "account", acc, "accPermissions", acc.Permissions, "perm", perm)
|
log.Info("Account does not have permission", "account", acc, "accPermissions", acc.Permissions, "perm", perm)
|
||||||
if state == nil {
|
if state == nil {
|
||||||
panic("All known global permissions should be set!")
|
PanicSanity("All known global permissions should be set!")
|
||||||
}
|
}
|
||||||
log.Info("Querying GlobalPermissionsAddress")
|
log.Info("Querying GlobalPermissionsAddress")
|
||||||
return HasPermission(nil, state.GetAccount(ptypes.GlobalPermissionsAddress), perm)
|
return HasPermission(nil, state.GetAccount(ptypes.GlobalPermissionsAddress), perm)
|
||||||
|
|
|
@ -30,9 +30,8 @@ func voteToStep(vote *types.Vote) int8 {
|
||||||
case types.VoteTypePrecommit:
|
case types.VoteTypePrecommit:
|
||||||
return stepPrecommit
|
return stepPrecommit
|
||||||
default:
|
default:
|
||||||
// SANITY CHECK (binary decoding should catch bad vote types
|
PanicSanity("Unknown vote type")
|
||||||
// before they get here (right?!)
|
return 0
|
||||||
panic("Unknown vote type")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,14 +94,13 @@ func (privVal *PrivValidator) Save() {
|
||||||
|
|
||||||
func (privVal *PrivValidator) save() {
|
func (privVal *PrivValidator) save() {
|
||||||
if privVal.filePath == "" {
|
if privVal.filePath == "" {
|
||||||
// SANITY CHECK
|
PanicSanity("Cannot save PrivValidator: filePath not set")
|
||||||
panic("Cannot save PrivValidator: filePath not set")
|
|
||||||
}
|
}
|
||||||
jsonBytes := binary.JSONBytes(privVal)
|
jsonBytes := binary.JSONBytes(privVal)
|
||||||
err := WriteFileAtomic(privVal.filePath, jsonBytes)
|
err := WriteFileAtomic(privVal.filePath, jsonBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// `@; BOOM!!!
|
// `@; BOOM!!!
|
||||||
panic(err)
|
PanicCrisis(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,8 +92,7 @@ func (s *State) Save() {
|
||||||
binary.WriteByteSlice(s.validatorInfos.Hash(), buf, n, err)
|
binary.WriteByteSlice(s.validatorInfos.Hash(), buf, n, err)
|
||||||
binary.WriteByteSlice(s.nameReg.Hash(), buf, n, err)
|
binary.WriteByteSlice(s.nameReg.Hash(), buf, n, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
// SOMETHING HAS GONE HORRIBLY WRONG
|
PanicCrisis(*err)
|
||||||
panic(*err)
|
|
||||||
}
|
}
|
||||||
s.DB.Set(stateKey, buf.Bytes())
|
s.DB.Set(stateKey, buf.Bytes())
|
||||||
}
|
}
|
||||||
|
@ -216,14 +215,12 @@ func (s *State) unbondValidator(val *Validator) {
|
||||||
// Move validator to UnbondingValidators
|
// Move validator to UnbondingValidators
|
||||||
val, removed := s.BondedValidators.Remove(val.Address)
|
val, removed := s.BondedValidators.Remove(val.Address)
|
||||||
if !removed {
|
if !removed {
|
||||||
// SOMETHING HAS GONE HORRIBLY WRONG
|
PanicCrisis("Couldn't remove validator for unbonding")
|
||||||
panic("Couldn't remove validator for unbonding")
|
|
||||||
}
|
}
|
||||||
val.UnbondHeight = s.LastBlockHeight + 1
|
val.UnbondHeight = s.LastBlockHeight + 1
|
||||||
added := s.UnbondingValidators.Add(val)
|
added := s.UnbondingValidators.Add(val)
|
||||||
if !added {
|
if !added {
|
||||||
// SOMETHING HAS GONE HORRIBLY WRONG
|
PanicCrisis("Couldn't add validator for unbonding")
|
||||||
panic("Couldn't add validator for unbonding")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,35 +228,29 @@ func (s *State) rebondValidator(val *Validator) {
|
||||||
// Move validator to BondingValidators
|
// Move validator to BondingValidators
|
||||||
val, removed := s.UnbondingValidators.Remove(val.Address)
|
val, removed := s.UnbondingValidators.Remove(val.Address)
|
||||||
if !removed {
|
if !removed {
|
||||||
// SOMETHING HAS GONE HORRIBLY WRONG
|
PanicCrisis("Couldn't remove validator for rebonding")
|
||||||
panic("Couldn't remove validator for rebonding")
|
|
||||||
}
|
}
|
||||||
val.BondHeight = s.LastBlockHeight + 1
|
val.BondHeight = s.LastBlockHeight + 1
|
||||||
added := s.BondedValidators.Add(val)
|
added := s.BondedValidators.Add(val)
|
||||||
if !added {
|
if !added {
|
||||||
// SOMETHING HAS GONE HORRIBLY WRONG
|
PanicCrisis("Couldn't add validator for rebonding")
|
||||||
panic("Couldn't add validator for rebonding")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) releaseValidator(val *Validator) {
|
func (s *State) releaseValidator(val *Validator) {
|
||||||
// Update validatorInfo
|
// Update validatorInfo
|
||||||
valInfo := s.GetValidatorInfo(val.Address)
|
valInfo := s.GetValidatorInfo(val.Address)
|
||||||
// SANITY CHECK
|
|
||||||
if valInfo == nil {
|
if valInfo == nil {
|
||||||
panic("Couldn't find validatorInfo for release")
|
PanicSanity("Couldn't find validatorInfo for release")
|
||||||
}
|
}
|
||||||
// SANITY CHECK END
|
|
||||||
valInfo.ReleasedHeight = s.LastBlockHeight + 1
|
valInfo.ReleasedHeight = s.LastBlockHeight + 1
|
||||||
s.SetValidatorInfo(valInfo)
|
s.SetValidatorInfo(valInfo)
|
||||||
|
|
||||||
// Send coins back to UnbondTo outputs
|
// Send coins back to UnbondTo outputs
|
||||||
accounts, err := getOrMakeOutputs(s, nil, valInfo.UnbondTo)
|
accounts, err := getOrMakeOutputs(s, nil, valInfo.UnbondTo)
|
||||||
// SANITY CHECK
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("Couldn't get or make unbondTo accounts")
|
PanicSanity("Couldn't get or make unbondTo accounts")
|
||||||
}
|
}
|
||||||
// SANITY CHECK END
|
|
||||||
adjustByOutputs(accounts, valInfo.UnbondTo)
|
adjustByOutputs(accounts, valInfo.UnbondTo)
|
||||||
for _, acc := range accounts {
|
for _, acc := range accounts {
|
||||||
s.UpdateAccount(acc)
|
s.UpdateAccount(acc)
|
||||||
|
@ -268,19 +259,16 @@ func (s *State) releaseValidator(val *Validator) {
|
||||||
// Remove validator from UnbondingValidators
|
// Remove validator from UnbondingValidators
|
||||||
_, removed := s.UnbondingValidators.Remove(val.Address)
|
_, removed := s.UnbondingValidators.Remove(val.Address)
|
||||||
if !removed {
|
if !removed {
|
||||||
// SOMETHING HAS GONE HORRIBLY WRONG
|
PanicCrisis("Couldn't remove validator for release")
|
||||||
panic("Couldn't remove validator for release")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) destroyValidator(val *Validator) {
|
func (s *State) destroyValidator(val *Validator) {
|
||||||
// Update validatorInfo
|
// Update validatorInfo
|
||||||
valInfo := s.GetValidatorInfo(val.Address)
|
valInfo := s.GetValidatorInfo(val.Address)
|
||||||
// SANITY CHECK
|
|
||||||
if valInfo == nil {
|
if valInfo == nil {
|
||||||
panic("Couldn't find validatorInfo for release")
|
PanicSanity("Couldn't find validatorInfo for release")
|
||||||
}
|
}
|
||||||
// SANITY CHECK END
|
|
||||||
valInfo.DestroyedHeight = s.LastBlockHeight + 1
|
valInfo.DestroyedHeight = s.LastBlockHeight + 1
|
||||||
valInfo.DestroyedAmount = val.VotingPower
|
valInfo.DestroyedAmount = val.VotingPower
|
||||||
s.SetValidatorInfo(valInfo)
|
s.SetValidatorInfo(valInfo)
|
||||||
|
@ -290,8 +278,7 @@ func (s *State) destroyValidator(val *Validator) {
|
||||||
if !removed {
|
if !removed {
|
||||||
_, removed := s.UnbondingValidators.Remove(val.Address)
|
_, removed := s.UnbondingValidators.Remove(val.Address)
|
||||||
if !removed {
|
if !removed {
|
||||||
// SOMETHING HAS GONE HORRIBLY WRONG
|
PanicCrisis("Couldn't remove validator for destruction")
|
||||||
panic("Couldn't remove validator for destruction")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
func Tempfile(prefix string) (*os.File, string) {
|
func Tempfile(prefix string) (*os.File, string) {
|
||||||
file, err := ioutil.TempFile("", prefix)
|
file, err := ioutil.TempFile("", prefix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
PanicCrisis(err)
|
||||||
}
|
}
|
||||||
return file, file.Name()
|
return file, file.Name()
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,23 +42,19 @@ func (cache *TxCache) GetAccount(addr Word256) *vm.Account {
|
||||||
|
|
||||||
func (cache *TxCache) UpdateAccount(acc *vm.Account) {
|
func (cache *TxCache) UpdateAccount(acc *vm.Account) {
|
||||||
addr := acc.Address
|
addr := acc.Address
|
||||||
// SANITY CHECK
|
|
||||||
_, removed := vmUnpack(cache.accounts[addr])
|
_, removed := vmUnpack(cache.accounts[addr])
|
||||||
if removed {
|
if removed {
|
||||||
panic("UpdateAccount on a removed account")
|
PanicSanity("UpdateAccount on a removed account")
|
||||||
}
|
}
|
||||||
// SANITY CHECK END
|
|
||||||
cache.accounts[addr] = vmAccountInfo{acc, false}
|
cache.accounts[addr] = vmAccountInfo{acc, false}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cache *TxCache) RemoveAccount(acc *vm.Account) {
|
func (cache *TxCache) RemoveAccount(acc *vm.Account) {
|
||||||
addr := acc.Address
|
addr := acc.Address
|
||||||
// SANITY CHECK
|
|
||||||
_, removed := vmUnpack(cache.accounts[addr])
|
_, removed := vmUnpack(cache.accounts[addr])
|
||||||
if removed {
|
if removed {
|
||||||
panic("RemoveAccount on a removed account")
|
PanicSanity("RemoveAccount on a removed account")
|
||||||
}
|
}
|
||||||
// SANITY CHECK END
|
|
||||||
cache.accounts[addr] = vmAccountInfo{acc, true}
|
cache.accounts[addr] = vmAccountInfo{acc, true}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,8 +82,9 @@ func (cache *TxCache) CreateAccount(creator *vm.Account) *vm.Account {
|
||||||
cache.accounts[addr] = vmAccountInfo{account, false}
|
cache.accounts[addr] = vmAccountInfo{account, false}
|
||||||
return account
|
return account
|
||||||
} else {
|
} else {
|
||||||
// NONCE HANDLING SANITY CHECK OR SHA3 IS BROKEN
|
// either we've messed up nonce handling, or sha3 is broken
|
||||||
panic(Fmt("Could not create account, address already exists: %X", addr))
|
PanicSanity(Fmt("Could not create account, address already exists: %X", addr))
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,12 +105,10 @@ func (cache *TxCache) GetStorage(addr Word256, key Word256) Word256 {
|
||||||
|
|
||||||
// NOTE: Set value to zero to removed from the trie.
|
// NOTE: Set value to zero to removed from the trie.
|
||||||
func (cache *TxCache) SetStorage(addr Word256, key Word256, value Word256) {
|
func (cache *TxCache) SetStorage(addr Word256, key Word256, value Word256) {
|
||||||
// SANITY CHECK
|
|
||||||
_, removed := vmUnpack(cache.accounts[addr])
|
_, removed := vmUnpack(cache.accounts[addr])
|
||||||
if removed {
|
if removed {
|
||||||
panic("SetStorage() on a removed account")
|
PanicSanity("SetStorage() on a removed account")
|
||||||
}
|
}
|
||||||
// SANITY CHECK END
|
|
||||||
cache.storages[Tuple256{addr, key}] = value
|
cache.storages[Tuple256{addr, key}] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
acm "github.com/tendermint/tendermint/account"
|
acm "github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/binary"
|
||||||
|
. "github.com/tendermint/tendermint/common"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -77,8 +78,8 @@ func (v *Validator) CompareAccum(other *Validator) *Validator {
|
||||||
} else if bytes.Compare(v.Address, other.Address) > 0 {
|
} else if bytes.Compare(v.Address, other.Address) > 0 {
|
||||||
return other
|
return other
|
||||||
} else {
|
} else {
|
||||||
// SANITY CHECK
|
PanicSanity("Cannot compare identical validators")
|
||||||
panic("Cannot compare identical validators")
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,5 +117,6 @@ func (vc validatorCodec) Decode(r io.Reader, n *int64, err *error) interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vc validatorCodec) Compare(o1 interface{}, o2 interface{}) int {
|
func (vc validatorCodec) Compare(o1 interface{}, o2 interface{}) int {
|
||||||
panic("ValidatorCodec.Compare not implemented")
|
PanicSanity("ValidatorCodec.Compare not implemented")
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,10 +36,7 @@ func (part *Part) Hash() []byte {
|
||||||
return part.hash
|
return part.hash
|
||||||
} else {
|
} else {
|
||||||
hasher := ripemd160.New()
|
hasher := ripemd160.New()
|
||||||
_, err := hasher.Write(part.Bytes)
|
hasher.Write(part.Bytes) // doesn't err
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
part.hash = hasher.Sum(nil)
|
part.hash = hasher.Sum(nil)
|
||||||
return part.hash
|
return part.hash
|
||||||
}
|
}
|
||||||
|
@ -226,7 +223,7 @@ func (ps *PartSet) IsComplete() bool {
|
||||||
|
|
||||||
func (ps *PartSet) GetReader() io.Reader {
|
func (ps *PartSet) GetReader() io.Reader {
|
||||||
if !ps.IsComplete() {
|
if !ps.IsComplete() {
|
||||||
panic("Cannot GetReader() on incomplete PartSet")
|
PanicSanity("Cannot GetReader() on incomplete PartSet")
|
||||||
}
|
}
|
||||||
buf := []byte{}
|
buf := []byte{}
|
||||||
for _, part := range ps.parts {
|
for _, part := range ps.parts {
|
||||||
|
|
|
@ -305,7 +305,7 @@ type DupeoutTx struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *DupeoutTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
func (tx *DupeoutTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
||||||
panic("DupeoutTx has no sign bytes")
|
PanicSanity("DupeoutTx has no sign bytes")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *DupeoutTx) String() string {
|
func (tx *DupeoutTx) String() string {
|
||||||
|
@ -326,7 +326,7 @@ func TxID(chainID string, tx Tx) []byte {
|
||||||
func jsonEscape(str string) string {
|
func jsonEscape(str string) string {
|
||||||
escapedBytes, err := json.Marshal(str)
|
escapedBytes, err := json.Marshal(str)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(Fmt("Error json-escaping a string", str))
|
PanicSanity(Fmt("Error json-escaping a string", str))
|
||||||
}
|
}
|
||||||
return string(escapedBytes)
|
return string(escapedBytes)
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ func (vote *Vote) String() string {
|
||||||
case VoteTypePrecommit:
|
case VoteTypePrecommit:
|
||||||
typeString = "Precommit"
|
typeString = "Precommit"
|
||||||
default:
|
default:
|
||||||
panic("Unknown vote type")
|
PanicSanity("Unknown vote type")
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("Vote{%v/%02d/%v(%v) %X#%v %v}", vote.Height, vote.Round, vote.Type, typeString, Fingerprint(vote.BlockHash), vote.BlockParts, vote.Signature)
|
return fmt.Sprintf("Vote{%v/%02d/%v(%v) %X#%v %v}", vote.Height, vote.Round, vote.Type, typeString, Fingerprint(vote.BlockHash), vote.BlockParts, vote.Signature)
|
||||||
|
|
|
@ -116,7 +116,7 @@ func setGlobalPerm(appState AppState, acc *Account, args []byte) (output []byte,
|
||||||
permNum, perm := returnTwoArgs(args)
|
permNum, perm := returnTwoArgs(args)
|
||||||
vmAcc := appState.GetAccount(ptypes.GlobalPermissionsAddress256)
|
vmAcc := appState.GetAccount(ptypes.GlobalPermissionsAddress256)
|
||||||
if vmAcc == nil {
|
if vmAcc == nil {
|
||||||
panic("cant find the global permissions account")
|
PanicSanity("cant find the global permissions account")
|
||||||
}
|
}
|
||||||
permN := ptypes.PermFlag(Uint64FromWord256(permNum))
|
permN := ptypes.PermFlag(Uint64FromWord256(permNum))
|
||||||
if !ValidPermN(permN) {
|
if !ValidPermN(permN) {
|
||||||
|
|
|
@ -50,7 +50,7 @@ func (st *Stack) Push(d Word256) {
|
||||||
// currently only called after Sha3
|
// currently only called after Sha3
|
||||||
func (st *Stack) PushBytes(bz []byte) {
|
func (st *Stack) PushBytes(bz []byte) {
|
||||||
if len(bz) != 32 {
|
if len(bz) != 32 {
|
||||||
panic("Invalid bytes size: expected 32")
|
PanicSanity("Invalid bytes size: expected 32")
|
||||||
}
|
}
|
||||||
st.Push(LeftPadWord256(bz))
|
st.Push(LeftPadWord256(bz))
|
||||||
}
|
}
|
||||||
|
|
2
vm/vm.go
2
vm/vm.go
|
@ -141,7 +141,7 @@ func (vm *VM) Call(caller, callee *Account, code, input []byte, value int64, gas
|
||||||
err := transfer(callee, caller, value)
|
err := transfer(callee, caller, value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// data has been corrupted in ram
|
// data has been corrupted in ram
|
||||||
panic("Could not return value to caller")
|
PanicCrisis("Could not return value to caller")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue