question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add beacon chain / eth2.0 related NewType

See original GitHub issue

What is wrong?

https://github.com/ethereum/py-evm/pull/1373#discussion_r224107745 To make the types more explict!

How can it be fixed

  1. Time unit - Second - and also can be used for PoW chain?
  2. For beacon chain, some other NewType candidates: Slot, ShardID. And with the latest spec: ValidatorStatus, SpecialRecordType, ValidatorSetDeltaFlag.
  3. EDIT: Move to ethereum/eth-typing/

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
cburgdorfcommented, Dec 19, 2018

What do you think about making the beacon chain new types in eth/beacon/typing.py temporarily, and then move to eth-typing once we settle down?

Yes, that would be my preferred approach as well 👍

The types that I’m not 100% sure:

Ensuring that an API that expects Gwei isn’t called with Ether is exactly what NewTypes are for. The canonical example is usually this NASA bug where an API was called with miles that expected kilometers and caused the rocket to crash. This falls into the same category.

I would just simplify the names to

Ether = NewType('Ether', int)  # uint64
Gwei = NewType('Gwei', int)  # uint64
1reaction
cburgdorfcommented, Dec 18, 2018

is there any known solution to define: (i) the length of an integer (ii) unsigned/signed integer via type hinting?

No, mypy can not do these things. What it can do is to allow you different types for different intents and ensure to trace the flow of these to prevent the wrong one ending up at a wrong place.

Consider this:


def create_some_thing_unsigned() -> int:
    ...

def create_some_thing_signed() -> int:
    ...

def consume_something_unsigned(unsigned: int):
    ...

clearly we want to prevent the following situation:

x = create_something_signed()
consume_something_unsigned(x)  # runtime crash!

Mypy can help you with this if you create a NewType.

UnsignedInt = NewType('UnsignedInt', int)

def create_some_thing_unsigned() -> UnsignedInt:
    ...

def create_some_thing_signed() -> int:
    ...

def consume_something_unsigned(unsigned: UnsignedInt):
    ...

Now, if you’d try this again, mypy would yell at you because it knows that x is not of type UnsignedInt.

x = create_something_signed()
consume_something_unsigned(x)  # development time mypy error!
Read more comments on GitHub >

github_iconTop Results From Across the Web

The Ethereum 2.0 Beacon Chain is here. Now what?
A massive new structure is being built alongside Ethereum. The core of this is the Beacon Chain, which changes the consensus model to...
Read more >
Ethereum 2.0 FAQ
Ethereum 2.0, also called Eth2 or “The Beacon Chain”, is the next major change to the Ethereum blockchain, introducing a Proof-of-Stake consensus mechanism, ......
Read more >
The Beacon Chain
The Beacon Chain introduced proof-of-stake to Ethereum. This keeps Ethereum secure and earns validators more ETH in the process. In practice, staking involves ......
Read more >
K Semantic Model of Beacon Chain - Devcon Archive
Daejun Park gives an overview of the K-Semantic Model of the Beacon Chain. ... ETH2. 0 is evaluating libp2p gossipsub as a decentralized,...
Read more >
ETHEREUM 2.0 AND CHAINLINK: The Story So Far And ...
Activation occurs after the beacon chain processes the deposit receipt from ETH 1.0. Shard Chains (2021) - Sharding is planned for 2021.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found