Skip to content

Commit

Permalink
add IsContract() in state.V
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitprincess committed Oct 18, 2023
1 parent 300649a commit 3099fdf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions contract/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func Execute(execCtx context.Context, bs *state.BlockState, cdb ChainAccessor, t

// check validity of tx
var valid bool
if valid, err = validateTxType(txType, txAmount, len(txPayload), bi.ForkVersion, receiver.IsDeploy(), len(receiver.State().CodeHash) > 0); valid != true {
if valid, err = validateTxType(txType, txAmount, len(txPayload), bi.ForkVersion, receiver.IsDeploy(), receiver.IsContract()); valid != true {
return
}

Expand Down Expand Up @@ -259,7 +259,7 @@ func preloadWorker() {
}

// when deploy and call in same block and not deployed yet
if receiver.IsNew() || len(receiver.State().CodeHash) == 0 {
if receiver.IsNew() || !receiver.IsContract() {
// do not preload an executor for a contract that is not deployed yet
replyCh <- &preloadReply{tx, nil, nil}
continue
Expand Down Expand Up @@ -379,7 +379,7 @@ func useGas(version int32) bool {

func checkRedeploy(sender, receiver *state.V, contractState *state.ContractState) error {
// check if the contract exists
if len(receiver.State().CodeHash) == 0 || receiver.IsNew() {
if !receiver.IsContract() || receiver.IsNew() {
receiverAddr := types.EncodeAddress(receiver.ID())
ctrLgr.Warn().Str("error", "not found contract").Str("contract", receiverAddr).Msg("redeploy")
return newVmError(fmt.Errorf("not found contract %s", receiverAddr))
Expand Down
4 changes: 4 additions & 0 deletions state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ func (v *V) IsNew() bool {
return v.newOne
}

func (v *V) IsContract() bool {
return len(v.State().CodeHash) > 0
}

func (v *V) IsDeploy() bool {
return v.deploy&deployFlag != 0
}
Expand Down

0 comments on commit 3099fdf

Please sign in to comment.