Skip to content

Commit 8776687

Browse files
edmundnoblelarskuhtz
authored andcommitted
set consensus state in savepoint
1 parent 5ea38ae commit 8776687

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/Chainweb/Pact/Backend/ChainwebPactDb.hs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -751,18 +751,19 @@ createVersionedTable tablename db = do
751751

752752
setConsensusState :: SQ3.Database -> ConsensusState -> ExceptT LocatedSQ3Error IO ()
753753
setConsensusState db cs = do
754-
exec' db
755-
"INSERT INTO ConsensusState (blockheight, hash, payloadhash, safety) VALUES \
756-
\(?, ?, ?, ?);"
757-
(toRow "final" $ _consensusStateFinal cs)
758-
exec' db
759-
"INSERT INTO ConsensusState (blockheight, hash, payloadhash, safety) VALUES \
760-
\(?, ?, ?, ?);"
761-
(toRow "safe" $ _consensusStateSafe cs)
762-
exec' db
763-
"INSERT INTO ConsensusState (blockheight, hash, payloadhash, safety) VALUES \
764-
\(?, ?, ?, ?);"
765-
(toRow "latest" $ _consensusStateLatest cs)
754+
withSavepoint db SetConsensusSavePoint $ do
755+
exec' db
756+
"INSERT INTO ConsensusState (blockheight, hash, payloadhash, safety) VALUES \
757+
\(?, ?, ?, ?);"
758+
(toRow "final" $ _consensusStateFinal cs)
759+
exec' db
760+
"INSERT INTO ConsensusState (blockheight, hash, payloadhash, safety) VALUES \
761+
\(?, ?, ?, ?);"
762+
(toRow "safe" $ _consensusStateSafe cs)
763+
exec' db
764+
"INSERT INTO ConsensusState (blockheight, hash, payloadhash, safety) VALUES \
765+
\(?, ?, ?, ?);"
766+
(toRow "latest" $ _consensusStateLatest cs)
766767
where
767768
toRow safety SyncState {..} =
768769
[ SInt $ fromIntegral @BlockHeight @Int64 _syncStateHeight

src/Chainweb/Pact/Backend/Utils.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ data SavepointName
206206
| RewindSavePoint
207207
| InitSchemaSavePoint
208208
| ValidateBlockSavePoint
209+
| SetConsensusSavePoint
209210
deriving (Eq, Ord, Enum, Bounded)
210211

211212
instance Show SavepointName where
@@ -218,6 +219,7 @@ instance HasTextRepresentation SavepointName where
218219
toText RewindSavePoint = "rewind"
219220
toText InitSchemaSavePoint = "init-schema"
220221
toText ValidateBlockSavePoint = "validate-block"
222+
toText SetConsensusSavePoint = "set-consensus"
221223
{-# INLINE toText #-}
222224

223225
fromText "read-from" = pure ReadFromSavepoint
@@ -226,6 +228,7 @@ instance HasTextRepresentation SavepointName where
226228
fromText "rewind" = pure RewindSavePoint
227229
fromText "init-schema" = pure InitSchemaSavePoint
228230
fromText "validate-block" = pure ValidateBlockSavePoint
231+
fromText "set-consensus" = pure SetConsensusSavePoint
229232
fromText t = throwM $ TextFormatException
230233
$ "failed to decode SavepointName " <> t
231234
<> ". Valid names are " <> T.intercalate ", " (toText @SavepointName <$> [minBound .. maxBound])

0 commit comments

Comments
 (0)