-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.go
64 lines (54 loc) · 1.85 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package arbnode
import (
"context"
"fmt"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/offchainlabs/nitro/arbutil"
"github.com/offchainlabs/nitro/staker"
"github.com/offchainlabs/nitro/validator"
"github.com/offchainlabs/nitro/validator/server_api"
)
type BlockValidatorAPI struct {
val *staker.BlockValidator
}
func (a *BlockValidatorAPI) LatestValidated(ctx context.Context) (*staker.GlobalStateValidatedInfo, error) {
return a.val.ReadLastValidatedInfo()
}
type BlockValidatorDebugAPI struct {
val *staker.StatelessBlockValidator
}
type ValidateBlockResult struct {
Valid bool `json:"valid"`
Latency string `json:"latency"`
GlobalState validator.GoGlobalState `json:"globalstate"`
}
func (a *BlockValidatorDebugAPI) ValidateMessageNumber(
ctx context.Context, msgNum hexutil.Uint64, full bool, moduleRootOptional *common.Hash,
) (ValidateBlockResult, error) {
result := ValidateBlockResult{}
var moduleRoot common.Hash
if moduleRootOptional != nil {
moduleRoot = *moduleRootOptional
} else {
var err error
moduleRoot, err = a.val.GetLatestWasmModuleRoot(ctx)
if err != nil {
return result, fmt.Errorf("no latest WasmModuleRoot configured, must provide parameter: %w", err)
}
}
start_time := time.Now()
valid, gs, err := a.val.ValidateResult(ctx, arbutil.MessageIndex(msgNum), full, moduleRoot)
result.Latency = fmt.Sprintf("%vms", time.Since(start_time).Milliseconds())
if gs != nil {
result.GlobalState = *gs
}
result.Valid = valid
return result, err
}
func (a *BlockValidatorDebugAPI) ValidationInputsAt(ctx context.Context, msgNum hexutil.Uint64, target ethdb.WasmTarget,
) (server_api.InputJSON, error) {
return a.val.ValidationInputsAt(ctx, arbutil.MessageIndex(msgNum), target)
}