@@ -798,6 +798,7 @@ export function findLatestProcessMemoryWith ({
798
798
PROCESS_IGNORE_ARWEAVE_CHECKPOINTS ,
799
799
IGNORE_ARWEAVE_CHECKPOINTS ,
800
800
PROCESS_CHECKPOINT_TRUSTED_OWNERS ,
801
+ PROCESS_CHECKPOINT_PREFERRED_OWNERS ,
801
802
logger : _logger ,
802
803
readStateFromCheckpoint,
803
804
hashWasmMemory,
@@ -851,15 +852,22 @@ export function findLatestProcessMemoryWith ({
851
852
}
852
853
`
853
854
854
- const removeIgnoredCheckpoints = ( { checkpoints } ) => {
855
- if ( ! checkpoints || ! checkpoints . length ) return { checkpoints : [ ] }
856
- return { checkpoints : checkpoints . filter ( ( checkpoint ) => ! isCheckpointIgnored ( checkpoint . node . id ) ) }
855
+ const removeIgnoredCheckpoints = ( { checkpoints, preferredCheckponts } ) => {
856
+ if ( ! checkpoints || ! checkpoints . length ) return { checkpoints : [ ] , preferredCheckponts }
857
+ return { checkpoints : checkpoints . filter ( ( checkpoint ) => ! isCheckpointIgnored ( checkpoint . node . id ) ) , preferredCheckponts }
857
858
}
858
859
859
- const findLatestVerified = async ( { checkpoints } ) => {
860
- if ( checkpoints . length <= CHECKPONT_VALIDATION_STEPS + CHECKPONT_VALIDATION_RETRIES ) {
861
- if ( checkpoints . length >= 1 ) {
862
- const sorted = checkpoints . sort ( ( a , b ) => {
860
+ const removeIgnoredPreferredCheckpoints = ( { checkpoints, preferredCheckponts } ) => {
861
+ if ( ! preferredCheckponts || ! preferredCheckponts . length ) return { checkpoints, preferredCheckponts : [ ] }
862
+ return { checkpoints, preferredCheckponts : preferredCheckponts . filter ( ( checkpoint ) => ! isCheckpointIgnored ( checkpoint . node . id ) ) }
863
+ }
864
+
865
+ const findLatestVerified = async ( { checkpoints, preferredCheckponts } ) => {
866
+ const checkpointsToUse = preferredCheckponts . length > 0 ? preferredCheckponts : checkpoints
867
+
868
+ if ( checkpointsToUse . length <= CHECKPONT_VALIDATION_STEPS + CHECKPONT_VALIDATION_RETRIES ) {
869
+ if ( checkpointsToUse . length >= 1 ) {
870
+ const sorted = checkpointsToUse . sort ( ( a , b ) => {
863
871
return parseInt (
864
872
b . node . tags . find ( ( tag ) => tag . name === 'Nonce' ) . value ) - parseInt ( a . node . tags . find ( ( tag ) => tag . name === 'Nonce' ) . value
865
873
)
@@ -890,8 +898,8 @@ export function findLatestProcessMemoryWith ({
890
898
}
891
899
}
892
900
893
- logger ( `FINDING LATEST VERIFIED CHECKPOINT FROM LIST OF CHECKPOINTS OF LENGTH ${ checkpoints . length } ` )
894
- const oldestToNewestCheckpoints = [ ...checkpoints ] . reverse ( ) . sort ( ( a , b ) => {
901
+ logger ( `FINDING LATEST VERIFIED CHECKPOINT FROM LIST OF CHECKPOINTS OF LENGTH ${ checkpointsToUse . length } ` )
902
+ const oldestToNewestCheckpoints = [ ...checkpointsToUse ] . reverse ( ) . sort ( ( a , b ) => {
895
903
return parseInt (
896
904
a . node . tags . find ( ( tag ) => tag . name === 'Nonce' ) . value ) - parseInt ( b . node . tags . find ( ( tag ) => tag . name === 'Nonce' ) . value
897
905
)
@@ -959,7 +967,7 @@ export function findLatestProcessMemoryWith ({
959
967
currentCheckpoint = nextCheckpoint
960
968
}
961
969
962
- if ( ( correct / CHECKPONT_VALIDATION_STEPS ) > CHECKPONT_VALIDATION_THRESH ) {
970
+ if ( ( correct / CHECKPONT_VALIDATION_STEPS ) >= CHECKPONT_VALIDATION_THRESH ) {
963
971
const finalTags = parseTags ( currentCheckpoint . node . tags )
964
972
logger ( `Determined correct checkpoint id: ${ currentCheckpoint . node . id } Process: ${ finalTags . Process } ` )
965
973
logger ( `Votes: ${ correct } ` )
@@ -998,9 +1006,10 @@ export function findLatestProcessMemoryWith ({
998
1006
return true
999
1007
}
1000
1008
1001
- const determineLatestVerifiedCheckpoint = ( checkpoints ) => {
1002
- return of ( { checkpoints } )
1009
+ const determineLatestVerifiedCheckpoint = ( { checkpoints, preferredCheckponts } ) => {
1010
+ return of ( { checkpoints, preferredCheckponts } )
1003
1011
. map ( removeIgnoredCheckpoints )
1012
+ . map ( removeIgnoredPreferredCheckpoints )
1004
1013
. chain ( fromPromise ( findLatestVerified ) )
1005
1014
}
1006
1015
@@ -1252,7 +1261,7 @@ export function findLatestProcessMemoryWith ({
1252
1261
return Rejected ( args )
1253
1262
}
1254
1263
1255
- return of ( { PROCESS_CHECKPOINT_TRUSTED_OWNERS } )
1264
+ return of ( { PROCESS_CHECKPOINT_TRUSTED_OWNERS , PROCESS_CHECKPOINT_PREFERRED_OWNERS } )
1256
1265
. chain ( ( { PROCESS_CHECKPOINT_TRUSTED_OWNERS } ) => {
1257
1266
if ( isEmpty ( PROCESS_CHECKPOINT_TRUSTED_OWNERS ) ) return address ( )
1258
1267
return Resolved ( PROCESS_CHECKPOINT_TRUSTED_OWNERS )
@@ -1267,6 +1276,28 @@ export function findLatestProcessMemoryWith ({
1267
1276
} )
1268
1277
} )
1269
1278
. map ( path ( [ 'data' , 'transactions' , 'edges' ] ) )
1279
+ . chain ( ( nonPreferredCheckpoints ) => {
1280
+ if ( isEmpty ( PROCESS_CHECKPOINT_PREFERRED_OWNERS ) ) {
1281
+ return of ( { checkpoints : nonPreferredCheckpoints , preferredCheckponts : [ ] } )
1282
+ }
1283
+ return of ( PROCESS_CHECKPOINT_PREFERRED_OWNERS )
1284
+ . map ( ( owners ) => ifElse ( Array . isArray , always ( owners ) , always ( [ owners ] ) ) ( owners ) )
1285
+ . chain ( ( owners ) => {
1286
+ return queryCheckpoints ( {
1287
+ query : GET_AO_PROCESS_CHECKPOINTS ,
1288
+ variables : { owners, processId, limit : 50 } ,
1289
+ processId,
1290
+ before : LATEST
1291
+ } )
1292
+ } )
1293
+ . map ( path ( [ 'data' , 'transactions' , 'edges' ] ) )
1294
+ . map ( ( preferredCheckponts ) => {
1295
+ return {
1296
+ checkpoints : nonPreferredCheckpoints ,
1297
+ preferredCheckponts
1298
+ }
1299
+ } )
1300
+ } )
1270
1301
. chain ( determineLatestVerifiedCheckpoint )
1271
1302
. bimap (
1272
1303
( err ) => {
0 commit comments