Skip to content

Commit

Permalink
Merge pull request #1743 from opentensor/release/6.9.2
Browse files Browse the repository at this point in the history
Release/6.9.2
  • Loading branch information
ifrit98 authored Mar 8, 2024
2 parents b63d0c3 + 6762518 commit 9e7e872
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 19 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 6.9.2 / 2024-03-08

## What's Changed
* Change error into a warning if not using archive. Impossible to tell if local is lite or full node.


**Full Changelog**: https://github.com/opentensor/bittensor/compare/v6.9.1...v6.9.2


## 6.9.1 / 2024-03-08

## What's Changed
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.9.1
6.9.2
2 changes: 1 addition & 1 deletion bittensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
nest_asyncio.apply()

# Bittensor code and protocol version.
__version__ = "6.9.1"
__version__ = "6.9.2"

version_split = __version__.split(".")
__version_as_int__: int = (
Expand Down
17 changes: 9 additions & 8 deletions bittensor/metagraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,14 +505,15 @@ def sync(
# Initialize subtensor
subtensor = self._initialize_subtensor(subtensor)

cur_block = subtensor.get_current_block() # type: ignore
if block and block < (cur_block - 300):
bittensor.logging.error(
"Attempting to sync longer than 300 blocks ago on a non-archive node. Please use the 'archive' network for subtensor and retry."
)
raise ValueError(
"Attempting to sync longer than 300 blocks ago on a non-archive node. Please use the 'archive' network for subtensor and retry."
)
if (
subtensor.chain_endpoint != bittensor.__archive_entrypoint__ # type: ignore
or subtensor.network != "archive" # type: ignore
):
cur_block = subtensor.get_current_block() # type: ignore
if block and block < (cur_block - 300):
bittensor.logging.warning(
"Attempting to sync longer than 300 blocks ago on a non-archive node. Please use the 'archive' network for subtensor and retry."
)

# Assign neurons based on 'lite' flag
self._assign_neurons(block, lite, subtensor)
Expand Down
41 changes: 32 additions & 9 deletions tests/unit_tests/test_metagraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from bittensor.metagraph import metagraph as Metagraph
from unittest.mock import MagicMock
from loguru import logger


@pytest.fixture
Expand Down Expand Up @@ -128,6 +129,8 @@ def test_process_weights_or_bonds(mock_environment):
@pytest.fixture
def mock_subtensor():
subtensor = MagicMock()
subtensor.chain_endpoint = bittensor.__finney_entrypoint__
subtensor.network = "finney"
subtensor.get_current_block.return_value = 601
return subtensor

Expand All @@ -142,18 +145,38 @@ def metagraph_instance():
return metagraph


@pytest.fixture
def loguru_sink():
class LogSink:
def __init__(self):
self.messages = []

def write(self, message):
# Assuming `message` is an object, you might need to adjust how you extract the text
self.messages.append(str(message))

def __contains__(self, item):
return any(item in message for message in self.messages)

return LogSink()


@pytest.mark.parametrize(
"block, test_id",
[
(300, "error_case_block_greater_than_300"),
(300, "warning_case_block_greater_than_300"),
],
)
def test_sync_error_cases(block, test_id, metagraph_instance, mock_subtensor):
# Arrange
# Act & Assert
with pytest.raises(ValueError) as excinfo:
metagraph_instance.sync(block=block, lite=True, subtensor=mock_subtensor)
def test_sync_warning_cases(
block, test_id, metagraph_instance, mock_subtensor, loguru_sink
):
handler_id = logger.add(loguru_sink.write, level="WARNING")

metagraph_instance.sync(block=block, lite=True, subtensor=mock_subtensor)

expected_message = "Attempting to sync longer than 300 blocks ago on a non-archive node. Please use the 'archive' network for subtensor and retry."
assert (
"Attempting to sync longer than 300 blocks ago on a non-archive node. Please use the 'archive' network for subtensor and retry."
in str(excinfo.value)
), f"Test ID: {test_id}"
expected_message in loguru_sink
), f"Test ID: {test_id} - Expected warning message not found in Loguru sink."

logger.remove(handler_id)

0 comments on commit 9e7e872

Please sign in to comment.