diff --git a/assertions/manager.go b/assertions/manager.go index f7eb1b5df..d056e8a6d 100644 --- a/assertions/manager.go +++ b/assertions/manager.go @@ -300,3 +300,9 @@ func randUint64(max uint64) (uint64, error) { } return n.Uint64(), nil } + +func (m *Manager) LatestAgreedAssertion() protocol.AssertionHash { + m.assertionChainData.RLock() + defer m.assertionChainData.RUnlock() + return m.assertionChainData.latestAgreedAssertion +} diff --git a/challenge-manager/manager.go b/challenge-manager/manager.go index ecd374f1f..e43d6fc95 100644 --- a/challenge-manager/manager.go +++ b/challenge-manager/manager.go @@ -520,3 +520,24 @@ func (m *Manager) fastTickWhileCatchingUp(ctx context.Context) { } } } + +func (m *Manager) LatestConfirmedState(ctx context.Context) (protocol.GoGlobalState, error) { + latestConfirmed, err := m.chain.LatestConfirmed(ctx, m.chain.GetCallOptsWithDesiredRpcHeadBlockNumber(&bind.CallOpts{Context: ctx})) + if err != nil { + return protocol.GoGlobalState{}, err + } + info, err := m.chain.ReadAssertionCreationInfo(ctx, latestConfirmed.Id()) + if err != nil { + return protocol.GoGlobalState{}, err + } + return protocol.GoExecutionStateFromSolidity(info.AfterState).GlobalState, nil +} + +func (m *Manager) LatestAgreedState(ctx context.Context) (protocol.GoGlobalState, error) { + latestAgreedAssertion := m.assertionManager.LatestAgreedAssertion() + info, err := m.chain.ReadAssertionCreationInfo(ctx, latestAgreedAssertion) + if err != nil { + return protocol.GoGlobalState{}, err + } + return protocol.GoExecutionStateFromSolidity(info.AfterState).GlobalState, nil +}