-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkpoint.py
58 lines (38 loc) · 1.18 KB
/
checkpoint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import boto3
import os
import json
CHECKPOINT_DELTA = 25200 #blocks
HEIGHT = 0
CLI_VERSION = '0'
with open('state.json', 'rb') as stateFile:
res = json.load(stateFile)
HEIGHT = res['height']
CLI_VERSION = res['version']
def getMaxCheckpoint():
maxHeight = 0
for obj in bucket.objects.all():
destruct = obj.key.split('-')
destruct[2] = int(destruct[2].split('.')[0])
if (destruct[0] == CLI_VERSION) and (destruct[2] > maxHeight):
maxHeight = destruct[2]
return maxHeight
def uploadCheckpoint():
filename = '{0}-mainnet-{1}.zip'.format(CLI_VERSION, str(HEIGHT))
print 'zippy zippy'
os.system('zip -r {0} neo-cli/Chain'.format(filename))
data = open(filename, 'rb')
print 'uploading'
bucket.put_object(Key=filename, Body=data, ACL='public-read')
data.close()
os.remove(filename)
print 'done'
s3 = boto3.resource('s3')
bucket = s3.Bucket('chainneo')
mCheckpoint = getMaxCheckpoint()
print 'max: {}'.format(mCheckpoint)
print 'height: {}'.format(HEIGHT)
if HEIGHT - mCheckpoint >= CHECKPOINT_DELTA:
print 'time to upload'
print HEIGHT
print mCheckpoint
uploadCheckpoint()