Skip to content

Commit

Permalink
WIP Endorsement -> Attestation
Browse files Browse the repository at this point in the history
  • Loading branch information
dmirgaleev committed May 2, 2024
1 parent d4975a3 commit ef05862
Show file tree
Hide file tree
Showing 23 changed files with 161 additions and 161 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,18 @@ The complete list of values allowed:
* `ballot`
* `delegation`
* `double_baking_evidence`
* `double_endorsement_evidence`
* `endorsement`
* `endorsement_with_slot`
* `double_attestation_evidence`
* `attestation`
* `attestation_with_slot`
* `origination`
* `proposals`
* `reveal`
* `seed_nonce_revelation`
* `transaction`
* `register_global_constant`
* `preendorsement`
* `preattestation`
* `set_deposits_limit`
* `double_preendorsement_evidence`
* `double_preattestation_evidence`
* `tx_rollup_origination`
* `tx_rollup_submit_batch`
* `tx_rollup_commit`
Expand Down
8 changes: 4 additions & 4 deletions build/dipdup.ghostnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ mempool:
ghostnet:
filters:
kinds:
- endorsement
- attestation
- transaction
- activate_account
- ballot
- delegation
- double_baking_evidence
- double_endorsement_evidence
- double_attestation_evidence
- origination
- proposals
- reveal
- seed_nonce_revelation
- register_global_constant
- set_deposits_limit
- preendorsement
- double_preendorsement_evidence
- preattestation
- double_preattestation_evidence
- tx_rollup_commit
- tx_rollup_dispatch_tickets
- tx_rollup_finalize_commitment
Expand Down
8 changes: 4 additions & 4 deletions build/dipdup.mainnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ mempool:
mainnet:
filters:
kinds:
- endorsement
- attestation
- transaction
- activate_account
- ballot
- delegation
- double_baking_evidence
- double_endorsement_evidence
- double_attestation_evidence
- origination
- proposals
- reveal
- seed_nonce_revelation
- register_global_constant
- set_deposits_limit
- preendorsement
- double_preendorsement_evidence
- preattestation
- double_preattestation_evidence
- tx_rollup_commit
- tx_rollup_dispatch_tickets
- tx_rollup_finalize_commitment
Expand Down
16 changes: 8 additions & 8 deletions build/dipdup.testnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ mempool:
ghostnet:
filters:
kinds:
- endorsement
- attestation
- transaction
- activate_account
- ballot
- delegation
- double_baking_evidence
- double_endorsement_evidence
- double_attestation_evidence
- origination
- proposals
- reveal
- seed_nonce_revelation
- register_global_constant
- set_deposits_limit
- preendorsement
- double_preendorsement_evidence
- preattestation
- double_preattestation_evidence
- tx_rollup_commit
- tx_rollup_dispatch_tickets
- tx_rollup_finalize_commitment
Expand Down Expand Up @@ -53,21 +53,21 @@ mempool:
oxfordnet:
filters:
kinds:
- endorsement
- attestation
- transaction
- activate_account
- ballot
- delegation
- double_baking_evidence
- double_endorsement_evidence
- double_attestation_evidence
- origination
- proposals
- reveal
- seed_nonce_revelation
- register_global_constant
- set_deposits_limit
- preendorsement
- double_preendorsement_evidence
- preattestation
- double_preattestation_evidence
- tx_rollup_commit
- tx_rollup_dispatch_tickets
- tx_rollup_finalize_commitment
Expand Down
8 changes: 4 additions & 4 deletions build/expected_metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ tables:
- bh2_proof_of_work_nonce

-
name: double_endorsings
name: double_attestations
columns:
- created_at
- updated_at
Expand All @@ -109,7 +109,7 @@ tables:
- op2_level

-
name: double_preendorsings
name: double_preattestations
columns:
- created_at
- updated_at
Expand Down Expand Up @@ -150,7 +150,7 @@ tables:
- destination

-
name: endorsements
name: attestations
columns:
- created_at
- updated_at
Expand Down Expand Up @@ -241,7 +241,7 @@ tables:
- storage

-
name: preendorsements
name: preattestations
columns:
- created_at
- updated_at
Expand Down
36 changes: 18 additions & 18 deletions cmd/mempool/bakers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,41 @@ import (
"github.com/dipdup-net/go-lib/node"
"github.com/dipdup-net/go-lib/tools/forge"
"github.com/dipdup-net/go-lib/tzkt/data"
"github.com/dipdup-net/mempool/cmd/mempool/endorsement"
"github.com/dipdup-net/mempool/cmd/mempool/attestation"

Check failure on line 13 in cmd/mempool/bakers.go

View workflow job for this annotation

GitHub Actions / Test

no required module provides package github.com/dipdup-net/mempool/cmd/mempool/attestation; to add it:
"github.com/dipdup-net/mempool/cmd/mempool/models"
"github.com/rs/zerolog/log"
)

const unknownBaker = "unknown"

func (indexer *Indexer) setEndorsementBakers(ctx context.Context) {
indexer.info().Msg("Thread for finding endorsement baker started")
func (indexer *Indexer) setAttestationBakers(ctx context.Context) {
indexer.info().Msg("Thread for finding attestation baker started")

for {
select {
case <-ctx.Done():
return
case endorsement := <-indexer.endorsements:
if len(endorsement.Errors) > 0 {
if err := indexer.findBaker(ctx, endorsement); err != nil {
case attestation := <-indexer.attestations:
if len(attestation.Errors) > 0 {
if err := indexer.findBaker(ctx, attestation); err != nil {
log.Err(err).Msg("find baker")
continue
}
} else {
endorsement.Baker = unknownBaker
attestation.Baker = unknownBaker
}
if _, err := indexer.db.DB().NewUpdate().
Model(endorsement).
Model(attestation).
WherePK().
Set("baker = ?", endorsement.Baker).
Set("baker = ?", attestation.Baker).
Exec(ctx); err != nil {
log.Err(err).Msg("set baker to endorsement")
log.Err(err).Msg("set baker to attestation")
}
}
}
}

func (indexer *Indexer) getEndorsingRights(ctx context.Context, level uint64) ([]data.Right, error) {
func (indexer *Indexer) getAttestationRights(ctx context.Context, level uint64) ([]data.Right, error) {
rights, err := indexer.rights.Fetch(fmt.Sprintf("rights/%s/%d", indexer.network, level), 15*time.Minute, func() (interface{}, error) {
rights, err := indexer.tzkt.Rights(ctx, level)
if err != nil {
Expand All @@ -64,26 +64,26 @@ func (indexer *Indexer) getEndorsingRights(ctx context.Context, level uint64) ([
}
}

func (indexer *Indexer) findBaker(ctx context.Context, e *models.Endorsement) error {
func (indexer *Indexer) findBaker(ctx context.Context, e *models.Attestation) error {
if err := indexer.delegates.Update(ctx, e.Level); err != nil {
return err
}

rights, err := indexer.getEndorsingRights(ctx, e.Level)
rights, err := indexer.getAttestationRights(ctx, e.Level)
if err != nil {
return err
}

forged, err := forge.Endorsement(node.Endorsement{
forged, err := forge.Attestation(node.Attestation{
Level: e.Level,
Metadata: &node.EndorsementMetadata{},
Metadata: &node.AttestationMetadata{},
}, e.Branch)
if err != nil {
return err
}

hash := endorsement.Hash(indexer.chainID, forged)
decodedSignature := endorsement.DecodeSignature(e.Signature)
hash := attestation.Hash(indexer.chainID, forged)
decodedSignature := attestation.DecodeSignature(e.Signature)

for i := len(rights) - 1; i >= 0; i-- {
if rights[i].Slots == 0 {
Expand All @@ -94,7 +94,7 @@ func (indexer *Indexer) findBaker(ctx context.Context, e *models.Endorsement) er
if !ok {
continue
}
if !endorsement.CheckKey(publicKey.Prefix, publicKey.Key, decodedSignature, hash) {
if !attestation.CheckKey(publicKey.Prefix, publicKey.Key, decodedSignature, hash) {
continue
}
e.Baker = address
Expand Down
4 changes: 2 additions & 2 deletions cmd/mempool/cached_delegates.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"context"

"github.com/dipdup-net/mempool/cmd/mempool/endorsement"
"github.com/dipdup-net/mempool/cmd/mempool/attestation"
"github.com/dipdup-net/mempool/cmd/mempool/tzkt"
)

Expand Down Expand Up @@ -56,7 +56,7 @@ func (cd *CachedDelegates) Init(ctx context.Context) error {
for i := range delegates {
cd.Delegates[delegates[i].Address] = PublicKey{
Prefix: delegates[i].PublicKey[:4],
Key: endorsement.DecodePublicKey(delegates[i].PublicKey),
Key: attestation.DecodePublicKey(delegates[i].PublicKey),
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/mempool/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Indexer struct {
// Filters -
type Filters struct {
Accounts []*config.Alias[config.Contract] `validate:"max=50" yaml:"accounts"`
Kinds []string `validate:"required,min=1,dive,oneof=activate_account ballot delegation double_baking_evidence double_endorsement_evidence endorsement endorsement_with_slot origination proposals reveal seed_nonce_revelation transaction register_global_constant" yaml:"kinds"`
Kinds []string `validate:"required,min=1,dive,oneof=activate_account ballot delegation double_baking_evidence double_attestation_evidence attestation attestation_with_slot origination proposals reveal seed_nonce_revelation transaction register_global_constant" yaml:"kinds"`
}

// Addresses -
Expand Down
2 changes: 1 addition & 1 deletion cmd/mempool/endorsement/check.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package endorsement
package attestation

import (
"crypto/ecdsa"
Expand Down
20 changes: 10 additions & 10 deletions cmd/mempool/endorsement/check_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package endorsement
package attestation

import (
"testing"
Expand All @@ -14,15 +14,15 @@ func TestCheckKey(t *testing.T) {
key string
signature string
chainID string
endorsement models.Endorsement
attestation models.Attestation
want bool
}{
{
name: "ed25519",
key: "edpkuEhzJqdFBCWMw6TU3deADRK2fq3GuwWFUphwyH7ero1Na4oGFP",
signature: "siggEYDRoz7tiECt2fc1M75ieJNeVAP6MGHLhpyPpPue8EU3QYjYSJLnDoDPgxkmrjr6R33qGrAxLASwkyQqa1r3tc5mGPwT",
chainID: "NetXdQprcVkpaWU",
endorsement: models.Endorsement{
attestation: models.Attestation{
Level: 751292,
MempoolOperation: models.MempoolOperation{
Branch: "BMbpxQAU7Jat7g9ZnKrP3brgqFX6r2VX8PPXCxNbFZeURA6DbEF",
Expand All @@ -35,7 +35,7 @@ func TestCheckKey(t *testing.T) {
key: "sppk7bMuoa8w2LSKz3XEuPsKx1WavsMLCWgbWG9CZNAsJg9eTmkXRPd",
signature: "sigdoarpkht5iMuEHcUPnr9KWMuScWgsMru1amLHzyV4cDxXVCVxQw8dXDcKrvVPd9XbkK2aDzN4Dbo8EiP3ythKZNKCCwFf",
chainID: "NetXdQprcVkpaWU",
endorsement: models.Endorsement{
attestation: models.Attestation{
Level: 751179,
MempoolOperation: models.MempoolOperation{
Branch: "BM2JkusQmT885mqjKiJXfMJrgQXZTwoEsCM8tkuvGyJLPrSw2ih",
Expand All @@ -48,7 +48,7 @@ func TestCheckKey(t *testing.T) {
key: "p2pk66iTZwLmRPshQgUr2HE3RUzSFwAN5MNaBQ5rfduT1dGKXd25pNN",
signature: "sigTtssYjbVCgJR8WpiDgyg3dSuGF1STSjQLXxTSFiWzTGdS2CdFUBKZUbDwK42L1gsYYN8fqryXQAfuZVk1wknBaKhsNTZP",
chainID: "NetXdQprcVkpaWU",
endorsement: models.Endorsement{
attestation: models.Attestation{
Level: 751447,
MempoolOperation: models.MempoolOperation{
Branch: "BLp1dxsyPLc58x4cSMKGVevdQfgo9VBHy46kqnhsJSrNgteDPex",
Expand All @@ -61,7 +61,7 @@ func TestCheckKey(t *testing.T) {
key: "edpku4Jnsyp9geSL3W4xEwGhtTDjbM89Q7RyG43fftxzR3Cs4YY6K7",
signature: "signGt3ExC4ELXEvzuPwpBFmfyo4CEqKktawD9ZH6a7D9Tn7zg2Tt9L7HYAiWb8u9Yjs8MnUpNNzixpD2y9TYQxqYnQzbp2s",
chainID: "NetXdQprcVkpaWU",
endorsement: models.Endorsement{
attestation: models.Attestation{
Level: 1479809,
MempoolOperation: models.MempoolOperation{
Branch: "BL38RNz32eAVhgvV5bUMWUxGMq2v2wkst9UaN7CbW7hLC6THCQ6",
Expand All @@ -73,9 +73,9 @@ func TestCheckKey(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
data, err := forge.Endorsement(node.Endorsement{Level: tt.endorsement.Level}, tt.endorsement.Branch)
data, err := forge.Attestation(node.Attestation{Level: tt.attestation.Level}, tt.attestation.Branch)
if err != nil {
t.Errorf("forge.Endorsement() err = %s", err.Error())
t.Errorf("forge.Attestation() err = %s", err.Error())
return
}
if got := CheckKey(tt.key[:4], DecodePublicKey(tt.key), DecodeSignature(tt.signature), Hash(tt.chainID, data)); got != tt.want {
Expand All @@ -89,14 +89,14 @@ func BenchmarkCheckKey(b *testing.B) {
key := DecodePublicKey("edpkuEhzJqdFBCWMw6TU3deADRK2fq3GuwWFUphwyH7ero1Na4oGFP")
signature := DecodeSignature("siggEYDRoz7tiECt2fc1M75ieJNeVAP6MGHLhpyPpPue8EU3QYjYSJLnDoDPgxkmrjr6R33qGrAxLASwkyQqa1r3tc5mGPwT")
chainID := "NetXdQprcVkpaWU"
endorsement := models.Endorsement{
attestation := models.Attestation{
Level: 751292,
MempoolOperation: models.MempoolOperation{
Branch: "BMbpxQAU7Jat7g9ZnKrP3brgqFX6r2VX8PPXCxNbFZeURA6DbEF",
Signature: "siggEYDRoz7tiECt2fc1M75ieJNeVAP6MGHLhpyPpPue8EU3QYjYSJLnDoDPgxkmrjr6R33qGrAxLASwkyQqa1r3tc5mGPwT",
},
}
data, err := forge.Endorsement(node.Endorsement{Level: endorsement.Level}, endorsement.Branch)
data, err := forge.Attestation(node.Attestation{Level: attestation.Level}, attestation.Branch)
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/mempool/endorsement/decode.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package endorsement
package attestation

import (
"github.com/btcsuite/btcutil/base58"
Expand Down
Loading

0 comments on commit ef05862

Please sign in to comment.