Skip to content

Commit

Permalink
Add Debug State Transition Method (#13495)
Browse files Browse the repository at this point in the history
* add it

* lint
  • Loading branch information
nisdas committed Jan 22, 2024
1 parent e610d2a commit 5a2453a
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion tools/pcli/main.go
Expand Up @@ -242,7 +242,7 @@ func main() {
blkRoot,
preStateRoot,
)
postState, err := transition.ExecuteStateTransition(context.Background(), stateObj, block)
postState, err := debugStateTransition(context.Background(), stateObj, block)
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -355,3 +355,32 @@ func benchmarkHash(sszPath string, sszType string) {
log.Fatal("Invalid type")
}
}

func debugStateTransition(
ctx context.Context,
st state.BeaconState,
signed interfaces.ReadOnlySignedBeaconBlock,
) (state.BeaconState, error) {
var err error

parentRoot := signed.Block().ParentRoot()
st, err = transition.ProcessSlotsUsingNextSlotCache(ctx, st, parentRoot[:], signed.Block().Slot())
if err != nil {
return st, errors.Wrap(err, "could not process slots")
}

// Execute per block transition.
set, st, err := transition.ProcessBlockNoVerifyAnySig(ctx, st, signed)
if err != nil {
return st, errors.Wrap(err, "could not process block")
}
var valid bool
valid, err = set.VerifyVerbosely()
if err != nil {
return st, errors.Wrap(err, "could not batch verify signature")
}
if !valid {
return st, errors.New("signature in block failed to verify")
}
return st, nil
}

0 comments on commit 5a2453a

Please sign in to comment.