diff --git a/common/context.go b/common/context.go index 55d4e4d7d..c7db8e8c8 100644 --- a/common/context.go +++ b/common/context.go @@ -23,7 +23,7 @@ type BlockContext struct { ChainContext *ChainContext // Height gets the height of the current block. Height int64 - // Timestamp is a timestamp of the current block. + // Timestamp is a timestamp of the current block, in seconds (UNIX epoch). // It is set by the block proposer, and therefore may not be accurate. // It should not be used for time-sensitive operations where incorrect // timestamps could result in security vulnerabilities. diff --git a/internal/services/jsonrpc/usersvc/service.go b/internal/services/jsonrpc/usersvc/service.go index d03ccae8e..aa557a614 100644 --- a/internal/services/jsonrpc/usersvc/service.go +++ b/internal/services/jsonrpc/usersvc/service.go @@ -705,7 +705,6 @@ func (svc *Service) Call(ctx context.Context, req *userjson.CallRequest) (*userj if err != nil { // NOTE: http api needs to be able to get the error message return nil, jsonrpc.NewError(jsonrpc.ErrorInvalidParams, "failed to convert action call: "+err.Error(), nil) - } // Authenticate by validating the challenge was server-issued, and verify @@ -752,6 +751,16 @@ func (svc *Service) Call(ctx context.Context, req *userjson.CallRequest) (*userj } } + chainStat, err := svc.chainClient.Status(ctx) + if err != nil { + return nil, jsonrpc.NewError(jsonrpc.ErrorNodeInternal, "failed to get chain status: "+err.Error(), nil) + } + height, stamp := chainStat.Sync.BestBlockHeight, chainStat.Sync.BestBlockTime.Unix() + if chainStat.Sync.Syncing { // don't use known stale height and time stamp if node is syncing + height = -1 + stamp = -1 + } + ctxExec, cancel := context.WithTimeout(ctx, svc.readTxTimeout) defer cancel() @@ -800,7 +809,8 @@ func (svc *Service) Call(ctx context.Context, req *userjson.CallRequest) (*userj Signer: signer, Caller: caller, BlockContext: &common.BlockContext{ - Height: -1, // cannot know the height here. + Height: height, + Timestamp: stamp, }, Authenticator: msg.AuthType, }, readTx, &common.ExecutionData{