mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-28 12:11:44 +00:00
some panics, dont panic on invalid opcode
This commit is contained in:
@ -293,15 +293,6 @@ func adjustByOutputs(accounts map[string]*account.Account, outs []*types.TxOutpu
|
|||||||
// If the tx is invalid, an error will be returned.
|
// If the tx is invalid, an error will be returned.
|
||||||
// Unlike ExecBlock(), state will not be altered.
|
// Unlike ExecBlock(), state will not be altered.
|
||||||
func ExecTx(blockCache *BlockCache, tx_ types.Tx, runCall bool, evc events.Fireable) error {
|
func ExecTx(blockCache *BlockCache, tx_ types.Tx, runCall bool, evc events.Fireable) error {
|
||||||
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
err := errors.New(Fmt("Recovered from panic in ExecTx", "err", r, "tx", tx_))
|
|
||||||
log.Error(err.Error())
|
|
||||||
// TODO return error
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// TODO: do something with fees
|
// TODO: do something with fees
|
||||||
fees := int64(0)
|
fees := int64(0)
|
||||||
_s := blockCache.State() // hack to access validators and block height
|
_s := blockCache.State() // hack to access validators and block height
|
||||||
@ -822,6 +813,10 @@ func ExecTx(blockCache *BlockCache, tx_ types.Tx, runCall bool, evc events.Firea
|
|||||||
|
|
||||||
// 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 *account.Account, perm ptypes.PermFlag) bool {
|
func HasPermission(state AccountGetter, acc *account.Account, perm ptypes.PermFlag) bool {
|
||||||
|
if perm > ptypes.AllBasePermissions {
|
||||||
|
panic("Checking an unknown permission in state should never happen")
|
||||||
|
}
|
||||||
|
|
||||||
if acc == nil {
|
if acc == nil {
|
||||||
// TODO
|
// TODO
|
||||||
// this needs to fall back to global or do some other specific things
|
// this needs to fall back to global or do some other specific things
|
||||||
@ -830,7 +825,10 @@ func HasPermission(state AccountGetter, acc *account.Account, perm ptypes.PermFl
|
|||||||
|
|
||||||
v, err := acc.Permissions.Base.Get(perm)
|
v, err := acc.Permissions.Base.Get(perm)
|
||||||
if _, ok := err.(ptypes.ErrValueNotSet); ok {
|
if _, ok := err.(ptypes.ErrValueNotSet); ok {
|
||||||
return HasPermission(state, state.GetAccount(ptypes.GlobalPermissionsAddress), perm)
|
if state == nil {
|
||||||
|
panic("All known global permissions should be set!")
|
||||||
|
}
|
||||||
|
return HasPermission(nil, state.GetAccount(ptypes.GlobalPermissionsAddress), perm)
|
||||||
}
|
}
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ func MakeGenesisState(db dbm.DB, genDoc *GenesisDoc) *State {
|
|||||||
if genDoc.Params != nil && genDoc.Params.GlobalPermissions != nil {
|
if genDoc.Params != nil && genDoc.Params.GlobalPermissions != nil {
|
||||||
globalPerms = genDoc.Params.GlobalPermissions
|
globalPerms = genDoc.Params.GlobalPermissions
|
||||||
// XXX: make sure the set bits are all true
|
// XXX: make sure the set bits are all true
|
||||||
// Without it the HasPermission() functions will recurse till death
|
// Without it the HasPermission() functions will fail
|
||||||
globalPerms.Base.SetBit = ptypes.AllSet
|
globalPerms.Base.SetBit = ptypes.AllSet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
vm/native.go
10
vm/native.go
@ -53,10 +53,7 @@ func sha256Func(input []byte, gas *int64) (output []byte, err error) {
|
|||||||
// Hash
|
// Hash
|
||||||
hasher := sha256.New()
|
hasher := sha256.New()
|
||||||
// CONTRACT: this does not err
|
// CONTRACT: this does not err
|
||||||
_, err = hasher.Write(input)
|
hasher.Write(input)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return hasher.Sum(nil), nil
|
return hasher.Sum(nil), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,10 +68,7 @@ func ripemd160Func(input []byte, gas *int64) (output []byte, err error) {
|
|||||||
// Hash
|
// Hash
|
||||||
hasher := ripemd160.New()
|
hasher := ripemd160.New()
|
||||||
// CONTRACT: this does not err
|
// CONTRACT: this does not err
|
||||||
_, err = hasher.Write(input)
|
hasher.Write(input)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return LeftPadBytes(hasher.Sum(nil), 32), nil
|
return LeftPadBytes(hasher.Sum(nil), 32), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
7
vm/vm.go
7
vm/vm.go
@ -90,11 +90,16 @@ func (vm *VM) EnablePermissions() {
|
|||||||
vm.perms = true
|
vm.perms = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX: it is the duty of the contract writer to call known permissions
|
||||||
|
// we do not convey if a permission is not set
|
||||||
|
// (unlike in state/execution, where we guarantee HasPermission is called
|
||||||
|
// on known permissions and panics else)
|
||||||
func HasPermission(appState AppState, acc *Account, perm ptypes.PermFlag) bool {
|
func HasPermission(appState AppState, acc *Account, perm ptypes.PermFlag) bool {
|
||||||
v, err := acc.Permissions.Base.Get(perm)
|
v, err := acc.Permissions.Base.Get(perm)
|
||||||
if _, ok := err.(ptypes.ErrValueNotSet); ok {
|
if _, ok := err.(ptypes.ErrValueNotSet); ok {
|
||||||
if appState == nil {
|
if appState == nil {
|
||||||
panic(fmt.Sprintf("Global permission value not set for %b", perm))
|
fmt.Printf("\n\n***** Unknown permission %b! ********\n\n", perm)
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
return HasPermission(nil, appState.GetAccount(ptypes.GlobalPermissionsAddress256), perm)
|
return HasPermission(nil, appState.GetAccount(ptypes.GlobalPermissionsAddress256), perm)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user