Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
proto_path
Browse files Browse the repository at this point in the history
janmasrovira committed Oct 28, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 4e44306 commit 4e4876c
Showing 7 changed files with 29 additions and 45 deletions.
2 changes: 1 addition & 1 deletion app/Commands/Dev/Nockma/Options.hs
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ parseNockmaCommand =
runInfo =
info
(NockmaRun <$> parseNockmaRunOptions)
(progDesc "Run an Anoma program. It should be used with artefacts obtained from compilation with the anoma target.")
(progDesc ("Run an Anoma program. It should be used with artefacts obtained from compilation with the anoma target. If the --" <> anomaDirOptLongStr <> " is given, then it runs the code in an anoma node"))

commandFromAsm :: Mod CommandFields NockmaCommand
commandFromAsm = command "eval" fromAsmInfo
36 changes: 14 additions & 22 deletions app/Commands/Dev/Nockma/Run.hs
Original file line number Diff line number Diff line change
@@ -17,29 +17,21 @@ runCommand opts = do
parsedTerm <- runAppError @JuvixError (Nockma.cueJammedFileOrPretty afile)
case parsedTerm of
TermAtom {} -> exitFailMsg "Expected nockma input to be a cell"
t@(TermCell {})
| opts ^. nockmaRunAnoma -> do
anomaDir <- getAnomaPath
runInAnoma anomaDir t (unfoldTuple parsedArgs)
| otherwise -> do
let formula = anomaCallTuple parsedArgs
(counts, res) <-
runOpCounts
. runReader defaultEvalOptions
. runOutputSem @(Term Natural) (logInfo . mkAnsiText . ppTrace)
$ evalCompiledNock' t formula
putStrLn (ppPrint res)
let statsFile = replaceExtension' ".profile" afile
writeFileEnsureLn statsFile (prettyText counts)
t@(TermCell {}) -> case opts ^. nockmaRunAnomaDir of
Just path -> do
anomaDir <- AnomaPath <$> fromAppPathDir path
runInAnoma anomaDir t (unfoldTuple parsedArgs)
Nothing -> do
let formula = anomaCallTuple parsedArgs
(counts, res) <-
runOpCounts
. runReader defaultEvalOptions
. runOutputSem @(Term Natural) (logInfo . mkAnsiText . ppTrace)
$ evalCompiledNock' t formula
putStrLn (ppPrint res)
let statsFile = replaceExtension' ".profile" afile
writeFileEnsureLn statsFile (prettyText counts)
where
getAnomaPath :: Sem r AnomaPath
getAnomaPath = do
apppath <- maybe err return (opts ^. nockmaRunAnomaDir)
AnomaPath <$> fromAppPathDir apppath
where
err :: Sem r x
err = exitFailMsg ("The --" <> anomaDirOptLongStr <> " must be provided")

inputFile :: AppPath File
inputFile = opts ^. nockmaRunFile

6 changes: 0 additions & 6 deletions app/Commands/Dev/Nockma/Run/Options.hs
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@ data NockmaRunOptions = NockmaRunOptions
{ _nockmaRunFile :: AppPath File,
_nockmaRunAnomaDir :: Maybe (AppPath Dir),
_nockmaRunProfile :: Bool,
_nockmaRunAnoma :: Bool,
_nockmaRunArgs :: Maybe (AppPath File)
}
deriving stock (Data)
@@ -26,11 +25,6 @@ parseNockmaRunOptions = do
<> action "file"
)
pure AppPath {_pathIsInput = True, ..}
_nockmaRunAnoma <-
switch
( long "anoma"
<> help ("Run in Anoma node (makes --" <> anomaDirOptLongStr <> " mandatory)")
)
_nockmaRunAnomaDir <- optional anomaDirOpt
_nockmaRunProfile <-
switch
15 changes: 10 additions & 5 deletions src/Anoma/Effect/Base.hs
Original file line number Diff line number Diff line change
@@ -84,7 +84,7 @@ withSapwnAnomaNode ::
Sem r a
withSapwnAnomaNode body = withSystemTempFile "start.exs" $ \fp tmpHandle -> do
liftIO (B.hPutStr tmpHandle anomaStartExs)
hFlush tmpHandle
hClose tmpHandle
curDir <- getCurrentDir
asks (^. anomaPath) >>= setCurrentDir
withCreateProcess (cprocess (toFilePath fp)) $ \_stdin mstdout _stderr procHandle -> do
@@ -108,23 +108,25 @@ anomaRpc' msg = do
stdoutH = fromJust mstdout
inputbs = B.toStrict (encode msg)
liftIO (B.hPutStr stdinH inputbs)
hFlush stdinH
hClose stdinH
res <- eitherDecodeStrict <$> liftIO (B.hGetContents stdoutH)
case res of
Right r -> return r
Left err -> error (pack err)

grpcCliProcess :: (Members '[Reader AnomaPath] r) => Sem r CreateProcess
grpcCliProcess = do
protoFile <- relativeToAnomaDir relProtoFile
paths <- relativeToAnomaDir relProtoDir
return
( proc
"grpc_cli"
[ "call",
"--json_input",
"--json_output",
"--proto_path",
toFilePath paths,
"--protofiles",
toFilePath protoFile,
toFilePath relProtoFile,
"localhost:" <> show listenPort,
"Anoma.Protobuf.Intents.Prove"
]
@@ -133,8 +135,11 @@ grpcCliProcess = do
std_out = CreatePipe
}
where
relProtoDir :: Path Rel Dir
relProtoDir = $(mkRelDir "apps/anoma_protobuf/priv/protobuf")

relProtoFile :: Path Rel File
relProtoFile = $(mkRelFile "apps/anoma_protobuf/priv/protobuf/anoma.proto")
relProtoFile = $(mkRelFile "anoma.proto")

runAnoma :: forall r a. (Members '[Logger, EmbedIO] r) => AnomaPath -> Sem (Anoma ': r) a -> Sem r a
runAnoma anomapath body = runReader anomapath . runConcurrent . runProcess $
3 changes: 2 additions & 1 deletion src/Anoma/Effect/RunNockma.hs
Original file line number Diff line number Diff line change
@@ -56,5 +56,6 @@ runNockma prog inputs = do
_runNockPrivateInputs = args,
_runNockPublicInputs = []
}
res :: Rpc.Response <- anomaRpc (Aeson.toJSON msg) >>= fromJSON
let json = Aeson.toJSON msg
res :: Rpc.Response <- anomaRpc json >>= fromJSON
decodeJam64 (res ^. Rpc.proof)
8 changes: 0 additions & 8 deletions src/Anoma/Rpc/RunNock.hs
Original file line number Diff line number Diff line change
@@ -50,11 +50,3 @@ $( deriveJSON
)

makeLenses ''Response

example :: RunNock
example =
RunNock
{ _runNockJammedProgram = "jamjam",
_runNockPrivateInputs = [NockInputText "input"],
_runNockPublicInputs = [NockInputJammed "public"]
}
4 changes: 2 additions & 2 deletions src/Juvix/Prelude/Trace.hs
Original file line number Diff line number Diff line change
@@ -46,6 +46,6 @@ traceToFile fpath t a =
return a
{-# WARNING traceToFile "Using traceToFile" #-}

traceToFileM :: (Applicative m) => Path Abs File -> Text -> a -> m ()
traceToFileM fpath t a = pure (traceToFile fpath t a) $> ()
traceToFileM :: (Applicative m) => Path Abs File -> Text -> m ()
traceToFileM fpath t = pure (traceToFile fpath t ()) $> ()
{-# WARNING traceToFileM "Using traceFileM" #-}

0 comments on commit 4e4876c

Please sign in to comment.