This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Nick Drozd <drozd@bitwise.io>
- Loading branch information
1 parent
f59a570
commit cdbfd49
Showing
9 changed files
with
1,172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2018 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ----------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright 2018 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ----------------------------------------------------------------------------- | ||
|
||
import abc | ||
|
||
|
||
class Driver(metaclass=abc.ABCMeta): | ||
@abc.abstractmethod | ||
def __init__(self, engine): | ||
pass | ||
|
||
@abc.abstractmethod | ||
def start(self, endpoint): | ||
pass | ||
|
||
@abc.abstractmethod | ||
def stop(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright 2018 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ----------------------------------------------------------------------------- | ||
|
||
import abc | ||
|
||
|
||
class Engine(metaclass=abc.ABCMeta): | ||
@abc.abstractmethod | ||
def start(self, updates, service): | ||
'''Called after the engine is initialized, when a connection to the | ||
validator has been established. Notifications from the | ||
validator are sent along UPDATES. SERVICE is used to send | ||
requests to the validator. | ||
Args: | ||
updates (Queue) | ||
service (Service) | ||
''' | ||
|
||
@abc.abstractmethod | ||
def stop(self): | ||
'''Called before the engine is dropped in order to give the engine a | ||
chance to notify peers and clean up.''' | ||
|
||
@abc.abstractproperty | ||
def version(self): | ||
'''Get the version of this engine. | ||
Return: | ||
str | ||
''' | ||
|
||
@abc.abstractproperty | ||
def name(self): | ||
'''Get the name of the engine, typically the algorithm being | ||
implemented. | ||
Return: | ||
str | ||
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright 2018 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ----------------------------------------------------------------------------- | ||
|
||
|
||
class InvalidState(Exception): | ||
pass | ||
|
||
|
||
class ReceiveError(Exception): | ||
pass | ||
|
||
|
||
class UnknownBlock(Exception): | ||
pass | ||
|
||
|
||
class UnknownPeer(Exception): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
# Copyright 2018 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ----------------------------------------------------------------------------- | ||
|
||
import abc | ||
|
||
|
||
class Block: | ||
def __init__(self, block): | ||
self.block_id = block.block_id | ||
self.previous_id = block.previous_id | ||
self.signer_id = block.signer_id | ||
self.block_num = block.block_num | ||
self.payload = block.payload | ||
|
||
|
||
class Service(metaclass=abc.ABCMeta): | ||
'''Provides methods that allow the consensus engine to issue commands | ||
and requests.''' | ||
|
||
# -- P2P -- | ||
|
||
@abc.abstractmethod | ||
def send_to(self, peer_id, message_type, payload): | ||
'''Send a consensus message to a specific connected peer. | ||
Args: | ||
peer_id (bytes) | ||
message_type (str) | ||
payload (bytes) | ||
''' | ||
|
||
@abc.abstractmethod | ||
def broadcast(self, message_type, payload): | ||
'''Broadcast a message to all connected peers. | ||
Args: | ||
message_type (str) | ||
payload (bytes) | ||
''' | ||
|
||
# -- Block Creation -- | ||
|
||
@abc.abstractmethod | ||
def initialize_block(self, previous_id): | ||
'''Initialize a new block with PREVIOUS_ID and begin adding batches to | ||
it. If no PREVIOUS_ID is specified, the current head will be | ||
used. | ||
Args: | ||
previous_id (bytes or None) | ||
''' | ||
|
||
@abc.abstractmethod | ||
def finalize_block(self, data): | ||
'''Stop adding batches to the current block and finalize it. Include | ||
DATA in the block. If this call is successful, the consensus | ||
engine will receive it afterwards. | ||
Args: | ||
data (bytes) | ||
Return: | ||
bytes | ||
''' | ||
|
||
@abc.abstractmethod | ||
def cancel_block(self): | ||
'''Stop adding batches to the current block and abandon it.''' | ||
|
||
# -- Block Directives -- | ||
|
||
@abc.abstractmethod | ||
def check_blocks(self, priority): | ||
'''Update the prioritization of blocks to check to PRIORITY. | ||
Args: | ||
priority (list[bytes]) | ||
''' | ||
|
||
@abc.abstractmethod | ||
def commit_block(self, block_id): | ||
'''Update the block that should be committed. | ||
Args: | ||
block_id (bytes) | ||
''' | ||
|
||
@abc.abstractmethod | ||
def ignore_block(self, block_id): | ||
'''Signal that this block is no longer being committed. | ||
Args: | ||
block_id (bytes) | ||
''' | ||
|
||
@abc.abstractmethod | ||
def fail_block(self, block_id): | ||
'''Mark this block as invalid from the perspective of consensus. | ||
Args: | ||
block_id (bytes) | ||
''' | ||
|
||
# -- Queries -- | ||
|
||
@abc.abstractmethod | ||
def get_blocks(self, block_ids): | ||
'''Retrive consensus-related information about blocks. | ||
Args: | ||
block_ids (list[bytes]) | ||
Return: | ||
dict[bytes, block] | ||
''' | ||
|
||
@abc.abstractmethod | ||
def get_settings(self, block_id, settings): | ||
'''Read the value of settings as of the given block. | ||
Args: | ||
block_id (bytes) | ||
settings (list[str]) | ||
Return: | ||
dict[str, str] | ||
''' | ||
|
||
@abc.abstractmethod | ||
def get_state(self, block_id, addresses): | ||
'''Read values in state as of the given block. | ||
Args: | ||
block_id (bytes) | ||
addresses (list[str]) | ||
Return: | ||
dict[str, bytes] | ||
''' |
Oops, something went wrong.