datdotorg / datdot-node-rust

datdot blockchain node in rust
https://playproject.io/datdot-node-rust
GNU General Public License v3.0
48 stars 9 forks source link

Issues from running substrate & service #18

Closed ninabreznik closed 4 years ago

ninabreznik commented 4 years ago

newPin event

It seems like it doesn't log the correct user nor hypercore address. I get all event logs look the same (same user + same key (not matching the actual hypercore key)). The user account logged in the event seem to be always the one that gets finalized first (we're also creating users)

VIDEO 1 (watch first) https://www.loom.com/share/78305a4036804a14af3f67fa0c36e2f0


VIDEO 2 (watch next) https://www.loom.com/share/4bb8ab5e497c47ceb7b09734122d2688

jam10o-new commented 4 years ago

So, looking into the apps UI, I'm actually seeing all of the expected events seperately, so all the pins are happening successfully.

I can however replicate the same issue in datdot-service, which leads me to believe this is a bug in either @polkadot/api or our use of it.

         {"ApplyExtrinsic":6} : system.ExtrinsicSuccess [{"weight":10000,"class":"normal","paysFee":true}]
         {"ApplyExtrinsic":6} : datVerify.NewPin ["5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw","0xc463e0b2d4c1816242918adc2670915c16a8cd2125ae41d2b1e01696269e4219"]
         {"ApplyExtrinsic":6} : system.ExtrinsicSuccess [{"weight":10000,"class":"normal","paysFee":true}]
         {"ApplyExtrinsic":6} : datVerify.NewPin ["5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw","0xc463e0b2d4c1816242918adc2670915c16a8cd2125ae41d2b1e01696269e4219"]
         {"ApplyExtrinsic":6} : system.ExtrinsicSuccess [{"weight":10000,"class":"normal","paysFee":true}]
         {"ApplyExtrinsic":6} : datVerify.NewPin ["5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw","0xc463e0b2d4c1816242918adc2670915c16a8cd2125ae41d2b1e01696269e4219"]
         {"ApplyExtrinsic":6} : system.ExtrinsicSuccess [{"weight":10000,"class":"normal","paysFee":true}

Notice we are printing console.log('\t', phase.toString(),: ${section}.${method}, data.toString())

where {"ApplyExtrinsic":6} is the output of phase.toString() where "6" represents the index of the event - the fact that every line here outputs "6" indicates that these are indeed all the same event, which is probably not what we are expecting.

jam10o-new commented 4 years ago

@ninabreznik as recommended by Jaco we should probably not be reusing the same const registerSeeder = api.tx.datVerify.registerSeeder() for every call.

jam10o-new commented 4 years ago
  const keypairs = [ALICE, CHARLIE, DAVE, EVE, FERDIE, NEW_ACCOUNT]

  /* ------------------------------------------------------------------------

                                 EXTRINSICS

---------------------------------------------------------------------------- */

  /* -------------------------  TRANSACTIONS -------------------------------- */

  /* ---   registerSeeder()  --- */

async function registerSeederAccount(pair){
  const registerSeeder = api.tx.datVerify.registerSeeder()
  await promiseRerun(registerSeeder.signAndSend(pair, ({ events = [], status }) => {
    if (status.isFinalized) {
      events.forEach(({ phase, event: { data, method, section } }) => {
        console.log('\t', phase.toString(), `: ${section}.${method}`, data.toString())
      })
    }
  }))
}

for(const pairIndex in keypairs){
  await registerSeederAccount(keypairs[pairIndex])
}

^^ this refactoring fixes the issue for me.

jam10o-new commented 4 years ago

Re: part 2 - I should probably also clarify that currently we don't "pin" dats (as in assign an existing hypercore to a host) unless the host explicitly asks for one to host - which means if you register_seeder and there is nothing to host, you don't emit a newPin event. This behaviour will change (you declare capacity and you get a set of hypercores under that capacity which rotate over time, you need to watch for NewPins with your address) but currently newPin is only emitted as part of register_seeder and only iff there is data preregistered and available to pin.