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

fix: do not republish self key twice #3634

Merged
merged 3 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/ipfs-core/src/ipns/republisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ class IpnsRepublisher {
const keys = await this._keychain.listKeys()

for (const key of keys) {
if (key.name === 'self') {
continue
}
const pem = await this._keychain.exportKey(key.name, pass)
const privKey = await crypto.keys.import(pem, pass)

Expand Down
20 changes: 20 additions & 0 deletions packages/ipfs-core/test/name.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ describe('name', function () {
expect(republisher._republishEntries.calledTwice).to.equal(true)
})

it('should not republish self key twice', async function () {
const mockKeychain = {
listKeys: () => Promise.resolve([{ name: 'self' }])
}
republisher = new IpnsRepublisher(sinon.stub(), sinon.stub(), sinon.stub(), mockKeychain, {
initialBroadcastInterval: 500,
broadcastInterval: 1000,
pass: 'pass'
})
republisher._republishEntry = sinon.stub()

await republisher.start()
Copy link
Member

Choose a reason for hiding this comment

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

Does this need stopping?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is stopped in the afterEach (line 29), like remaining tests


expect(republisher._republishEntry.calledOnce).to.equal(false)

// Initial republish should happen after ~500ms
await delay(750)
Copy link
Member

Choose a reason for hiding this comment

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

Can we configure a smaller delay to make the tests faster?

Copy link
Member Author

Choose a reason for hiding this comment

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

changed to 200 with initial broadcast of 100

Copy link
Member Author

Choose a reason for hiding this comment

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

also decreased the other test timers

expect(republisher._republishEntry.calledOnce).to.equal(true)
})

it('should error if run republish again', async () => {
republisher = new IpnsRepublisher(sinon.stub(), sinon.stub(), sinon.stub(), sinon.stub(), {
initialBroadcastInterval: 50,
Expand Down