Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

NEAR support #210

Merged
merged 12 commits into from
Oct 22, 2021
Merged

NEAR support #210

merged 12 commits into from
Oct 22, 2021

Conversation

evaporei
Copy link
Contributor

@evaporei evaporei commented Sep 24, 2021

Ready for review, 🚨 don't merge 🚨 .

Based of the Receipt of this proto file.

We probably will address the TODO comments once the .proto file is up to date (which will require changes in multiple projects/repos, so that's for the end).

Solves: https://github.com/graphprotocol/graph-ts/issues/209

@evaporei evaporei self-assigned this Sep 24, 2021
@evaporei evaporei force-pushed the otavio/near branch 3 times, most recently from 06b026c to e5e6e8e Compare September 27, 2021 22:47
@evaporei evaporei changed the title WIP - NEAR support NEAR support Sep 27, 2021
@evaporei evaporei marked this pull request as ready for review September 27, 2021 22:50
@leoyvens
Copy link
Collaborator

Nice! One thing I think is worth adding already on this first pass the Block type, as a block: Block field in ReceiptWithOutcome, because it is very common to need at least basic info like block hash and number. And we'll need it anyways for block triggers. It can be a direct translation of the Block message https://github.com/streamingfast/proto-near/blob/develop/sf/near/codec/v1/codec.proto#L95.

chain/near.ts Outdated Show resolved Hide resolved
chain/near.ts Outdated Show resolved Hide resolved
chain/near.ts Outdated Show resolved Hide resolved
chain/near.ts Outdated Show resolved Hide resolved
chain/near.ts Outdated Show resolved Hide resolved
chain/near.ts Outdated Show resolved Hide resolved
chain/near.ts Outdated Show resolved Hide resolved
chain/near.ts Outdated

export class AccessKeyPermissionValue {
constructor(
public kind: AccessPermissionKind,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AccessPermissionKind is not defined anywhere.

Suggested change
public kind: AccessPermissionKind,
public kind: AccessKeyPermissionKind,

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're correct, just fixed the typo, thanks!


export class ExecutionOutcome {
constructor(
public proof: MerklePath,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MerklePath is not defined anywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added! Nice catch 🙂

chain/near.ts Outdated Show resolved Hide resolved
chain/near.ts Show resolved Hide resolved
@evaporei
Copy link
Contributor Author

evaporei commented Oct 13, 2021

@maoueh thanks for the review! Still, two of your comments should've been caught by the CI, I'll investigate why it didn't failed compiling near.ts.

Edit: I've added a build step to the CI so that errors like these are caught early. I'm still not 100% sure why the tests didn't have a compilation error, but I guess it's a compiler optimization to remove dead code from the asc (AS compiler) side.

This is needed because of the `class MerklePath extends
Array<MerklePathItem`.

The same had to be done for `Tuple` and `Value` in the `ethereum`
file/module.

AssemblyScript requires those implementations because of the
super class.
@maoueh
Copy link
Contributor

maoueh commented Oct 13, 2021

@otaviopace Missing pieces for global.ts

  ...
  ArrayF64 = 50,
  ArrayBigDecimal = 51,

  // NEAR
  NearSignature = 52,
  NearPublicKey = 53,
  NearFunctionCallPermission = 54,
  NearFullAccessPermission = 55,
  NearAccessKeyPermissionValue = 56,
  NearAccessKey = 57,
  NearDataReceiver = 58,
  NearCreateAccountAction = 59,
  NearDeployContractAction = 60,
  NearFunctionCallAction = 61,
  NearTransferAction = 62,
  NearStakeAction = 63,
  NearAddKeyAction = 64,
  NearDeleteKeyAction = 65,
  NearDeleteAccountAction = 66,
  NearActionValue = 67,
  NearActionReceipt = 68,
  NearSuccessStatus = 69,
  NearMerklePath = 70,
  NearExecutionOutcome = 71,
  NearSlashedValidator = 72,
  NearBlockHeader = 73,
  NearValidatorStake = 74,
  NearChunkHeader = 75,
  NearBlock = 76,
  NearReceiptWithOutcome = 77,
    ...
    case TypeId.ArrayF64:
      return idof<Array<f64>>()
    case TypeId.ArrayBigDecimal:
      return idof<Array<BigDecimal>>()

    // NEAR
    case TypeId.NearSignature:
      return idof<NearSignature>()
    case TypeId.NearPublicKey:
      return idof<NearPublicKey>()
    case TypeId.NearFunctionCallPermission:
      return idof<NearFunctionCallPermission>()
    case TypeId.NearFullAccessPermission:
      return idof<NearFullAccessPermission>()
    case TypeId.NearAccessKeyPermissionValue:
      return idof<NearAccessKeyPermissionValue>()
    case TypeId.NearAccessKey:
      return idof<NearAccessKey>()
    case TypeId.NearDataReceiver:
      return idof<NearDataReceiver>()
    case TypeId.NearCreateAccountAction:
      return idof<NearCreateAccountAction>()
    case TypeId.NearDeployContractAction:
      return idof<NearDeployContractAction>()
    case TypeId.NearFunctionCallAction:
      return idof<NearFunctionCallAction>()
    case TypeId.NearTransferAction:
      return idof<NearTransferAction>()
    case TypeId.NearStakeAction:
      return idof<NearStakeAction>()
    case TypeId.NearAddKeyAction:
      return idof<NearAddKeyAction>()
    case TypeId.NearDeleteKeyAction:
      return idof<NearDeleteKeyAction>()
    case TypeId.NearDeleteAccountAction:
      return idof<NearDeleteAccountAction>()
    case TypeId.NearActionValue:
      return idof<NearActionValue>()
    case TypeId.NearActionReceipt:
      return idof<NearActionReceipt>()
    case TypeId.NearSuccessStatus:
      return idof<NearSuccessStatus>()
    case TypeId.NearMerklePath:
      return idof<NearMerklePath>()
    case TypeId.NearExecutionOutcome:
      return idof<NearExecutionOutcome>()
    case TypeId.NearSlashedValidator:
      return idof<NearSlashedValidator>()
    case TypeId.NearBlockHeader:
      return idof<NearBlockHeader>()
    case TypeId.NearValidatorStake:
      return idof<NearValidatorStake>()
    case TypeId.NearChunkHeader:
      return idof<NearChunkHeader>()
    case TypeId.NearBlock:
      return idof<NearBlock>()
    case TypeId.NearReceiptWithOutcome:
      return idof<NearReceiptWithOutcome>()
      
    default:
      return 0
  }

chain/near.ts Outdated Show resolved Hide resolved
}
}

export class MerklePath extends Array<MerklePathItem> {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we actually get rid of MerklePath here, I'm not seeing the added benefits of having it. Maybe there is something else in play that I do not see.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to remove the proof field from the ExecutionOutcome class entirely? It seems to be the only place that uses it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, I'm wondering what is the correct Rust bindings for this one, is it AscPtr<AscMerklePath> or directly AscPtr<Array<AsckMerklePathItem>>?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to have the first one because it will be a new class, and that requires a new class identifier for the header.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll still wondering how such "extended" array should look like when generating the underlying AscMerklePath here. How to represent the "extends" fact. Will need you help to determine the correct mapping.

chain/near.ts Outdated Show resolved Hide resolved
chain/near.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@maoueh maoueh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left two more review comments.

chain/near.ts Outdated Show resolved Hide resolved
chain/near.ts Outdated
public outcomeRoot: CryptoHash,
public chunksIncluded: u64,
public challengesRoot: CryptoHash,
public timestampNanosec: u64,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the timestamp is missing, this is, AFAIK, only the nano sec of the timestamp so it kind of add up to the timestamp value in milliseconds (also to be validated) and adds extra precision.

We have the timestamp in the protobuf.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maoueh
Copy link
Contributor

maoueh commented Oct 21, 2021

And we need to update for the latest IndexTypeId global things.

evaporei and others added 4 commits October 22, 2021 09:07
The `test` script was not catching these for some reason
that's probably related to how the AssemblyScript compiles
code and removes unnecessary things (needs further investigation).

For now it's very much helpful (and needed) to catch compilation
errors on the CI step.
@evaporei evaporei merged commit f5d7ebd into master Oct 22, 2021
@evaporei evaporei deleted the otavio/near branch October 22, 2021 17:22
@evaporei evaporei mentioned this pull request Oct 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants