|
15 | 15 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
16 | 16 | # DEALINGS IN THE SOFTWARE. |
17 | 17 |
|
18 | | -__version__ = "0.2.1" |
| 18 | +__version__ = "0.2.2" |
19 | 19 |
|
20 | 20 | import enum |
21 | 21 | import json |
@@ -168,46 +168,57 @@ def get_path_to_fast_sync(cls) -> str: |
168 | 168 | def sync_and_save(self, console: Console, block_hash: str, filename: Optional[str] = None) -> None: |
169 | 169 | """Runs the fast sync binary to sync all neurons at a given block hash""" |
170 | 170 | FastSync.verify_fast_sync_support() |
171 | | - path_to_bin = FastSync.get_path_to_fast_sync() |
172 | 171 | console.print("Using subtensor-node-api for neuron retrieval...") |
173 | | - args = [path_to_bin, "sync_and_save", "-u", self.endpoint_url, '-b', block_hash] |
| 172 | + args = ["sync_and_save", "-u", self.endpoint_url, '-b', block_hash] |
174 | 173 | if filename is not None: |
175 | 174 | args.extend(['-f', filename]) |
176 | 175 | # will write to ~/.bittensor/metagraph.json by default |
| 176 | + self.__call_binary(console, args) |
| 177 | + |
| 178 | + def __call_binary(self, console: Console, args: List[str]) -> None: |
| 179 | + """ |
| 180 | + Calls the fast sync binary with the given args |
| 181 | +
|
| 182 | + Args: |
| 183 | + args: List of arguments to pass to the fast |
| 184 | + sync binary |
| 185 | +
|
| 186 | + Raises: |
| 187 | + FastSyncRuntimeException: If the fast sync binary fails |
| 188 | + """ |
| 189 | + FastSync.verify_fast_sync_support() |
| 190 | + path_to_bin = FastSync.get_path_to_fast_sync() |
| 191 | + args = [path_to_bin] + args |
177 | 192 | try: |
178 | | - subprocess.run(args, check=True, stdout=subprocess.PIPE) |
179 | | - except subprocess.SubprocessError as e: |
180 | | - raise FastSyncRuntimeException("Error running fast sync binary: {}".format(e)) |
| 193 | + subprocess.run(args, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 194 | + except subprocess.CalledProcessError as e: |
| 195 | + stderr = e.stderr.decode(sys.getfilesystemencoding()) |
| 196 | + raise FastSyncRuntimeException("Error running fast sync binary: {}\nSTDERR={}".format(e, stderr)) |
181 | 197 |
|
182 | 198 | def sync_and_save_historical(self, console: Console, block_numbers: List[Union[int, str]] = ["latest"], uids: List[int] = [], filename: Optional[str] = None) -> None: |
183 | 199 | """Runs the fast sync binary to sync all uids at each block number""" |
184 | 200 | FastSync.verify_fast_sync_support() |
185 | | - path_to_bin = FastSync.get_path_to_fast_sync() |
186 | 201 | console.print("Using subtensor-node-api for historical neuron retrieval...") |
187 | 202 | args = ( |
188 | | - [path_to_bin, "sync_and_save_historical", "-u", self.endpoint_url] + |
| 203 | + ["sync_and_save_historical", "-u", self.endpoint_url] + |
189 | 204 | (['-b'] + [str(bn) for bn in block_numbers]) + |
190 | | - (['-i'] + [str(uid) for uid in uids]) if len(uids) > 0 else [] + # uids are optional, default to all |
| 205 | + ((['-i'] + [str(uid) for uid in uids]) if len(uids) > 0 else []) + # uids are optional, default to all |
191 | 206 | (['-f', filename] if filename is not None else []) # will write to ~/.bittensor/metagraph_historical.json by default |
192 | 207 | ) |
193 | | - try: |
194 | | - subprocess.run(args, check=True, stdout=subprocess.PIPE) |
195 | | - except subprocess.SubprocessError as e: |
196 | | - raise FastSyncRuntimeException("Error running fast sync binary: {}".format(e)) |
| 208 | + |
| 209 | + console.print("Running fast sync binary with args: {}".format(args)) |
| 210 | + |
| 211 | + self.__call_binary(console, args) |
197 | 212 |
|
198 | 213 | def get_blockAtRegistration_for_all_and_save(self, console: Console, block_hash: str, filename: Optional[str] = None) -> None: |
199 | 214 | """Runs the fast sync binary to get blockAtRegistration for all neurons at a given block hash""" |
200 | 215 | FastSync.verify_fast_sync_support() |
201 | | - path_to_bin = FastSync.get_path_to_fast_sync() |
202 | 216 | console.print("Using subtensor-node-api for blockAtRegistration storage retrieval...") |
203 | | - args = [path_to_bin, "block_at_reg_and_save", "-u", self.endpoint_url, '-b', block_hash] |
| 217 | + args = ["block_at_reg_and_save", "-u", self.endpoint_url, '-b', block_hash] |
204 | 218 | if filename is not None: |
205 | 219 | args.extend(['-f', filename]) |
206 | 220 | # will write to ~/.bittensor/blockAtRegistration_all.json by default |
207 | | - try: |
208 | | - subprocess.run(args, check=True, stdout=subprocess.PIPE) |
209 | | - except subprocess.SubprocessError as e: |
210 | | - raise FastSyncRuntimeException("Error running fast sync binary: {}".format(e)) |
| 221 | + self.__call_binary(console, args) |
211 | 222 |
|
212 | 223 | @classmethod |
213 | 224 | def load_blockAtRegistration_for_all(cls, json_file_location: Optional[str] = '~/.bittensor/blockAtRegistration_all.json') -> List[int]: |
|
0 commit comments