โหนดที่ดูง่าย SWQoS
ฉากและการใช้งาน
In Solana การส่งธุรกรรม, การเลื่อนระดับ, การวางตําแหน่งผู้นํา, และการจราจรทางเครือข่ายอย่างต่อเนื่องเปลี่ยนแปลงซึ่งเส้นทางไปถึงผู้นําเร็วที่สุด นี่ไม่ได้ระบุถึงสิ่งใด RPC ผู้จัดจัดส่งหรือบริการส่ง; มันเป็นลักษณะโครงสร้างของ Solanaแบบประหาร
ERPC's SWQoS จุดปลายเป็นเส้นทางส่งที่ฉีด ธุรกรรมเข้าเลนความสําคัญ luffed โดยผู้นําพื้นฐานจากคุณภาพของบริการที่จับต้องได้ (Squatched buffice of Service)SWQoS.... ความสําคัญของแบนด์วิดท์นี้ประมาณ 5 กก.
ด้วยเหตุผลนั้น SWQoS จุด จบ คือ วิธี ที่ สําคัญ ใน การ ส่ง ข้อ ตก ลง ซื้อ ขาย แต่ ใน การ ผลิต จุด จบ เพียง จุด เดียว นั้น ไม่ ใช่ วิธี ที่ เร็ว ที่ สุด เสมอ ไป.
จากลักษณะเหล่านี้ รูปแบบการทํางานในการส่งธุรกิจเดียวกัน ไปหลายเส้นทางอย่างรวดเร็วในคู่ขนาน
อย่างไรก็ตาม เมื่อมีการส่งธุรกรรมเดียวกันไปยังที่สิ้นสุดหลายจุด คุณไม่สามารถรับประกันได้ว่า จะดําเนินการได้เพียงครั้งเดียวโดยไร้การควบคุม
Solana ให้ตําแหน่งที่ดูง่ายเป็นกลไกสําหรับนี้ การใช้ Nons ที่ดูง่ายจะช่วยให้คุณส่งรายการที่ลงนามในสัญญาผ่านหลายเส้นทาง ในขณะที่จํากัดการประหารชีวิตบน-จีนให้เป็นเวลาครั้งเดียว
หน้านี้อธิบายวิธีการดําเนินการแบบพัดลมออกที่รวม ERPC's SWQoS จุดปลายที่เร็วอื่น ๆ RPC จุดปลาย, สันนิษฐานการส่งธุรกิจกับ ดูโรเบิลน็อง
ขอบเขตและเงื่อนไข
มัคคุเทศก์นี้ครอบคลุมการสร้างบัญชี Nons ที่ดูง่ายด้วย web3js และใช้มันสําหรับการส่งและส่งออกไป
พรีครีชีส์ที่จะเข้าใจ:
- สําหรับรายการที่ดูง่าย ให้ใช้ค่าไม่สิ้นสุด
recentBlockhashและสถานที่nonceAdvanceในฐานะที่เป็นผู้สอนคนแรก - ครั้ง
nonceAdvanceประมวลผล, โหนดต่าง ๆ สามารถใช้ได้แม้ว่าคําสั่งในภายหลังจะล้มเหลว คุณไม่สามารถเรียกข้อมูลดิบเดิมได้ - การสร้างบัญชีแบบไม่สิ้นสุด เป็นการตั้งค่าแบบหนึ่งครั้ง และตามปกติจะถูกใช้ซ้ํา
ขั้น ที่ 1: เตรียม อํานาจ และ ความ เกี่ยว พัน
อํานาจที่มีอํานาจเป็นคีย์เพล ที่สามารถก้าวหน้าความไม่สงบ
typescript
import {
Connection,
Keypair,
SystemProgram,
NONCE_ACCOUNT_LENGTH,
} from '@solana/web3.js'
const connection = new Connection(
'https://<primary-rpc-endpoint>',
'confirmed',
)
const nonceAuthority = Keypair.fromSecretKey(/* secret key */)import {
Connection,
Keypair,
SystemProgram,
NONCE_ACCOUNT_LENGTH,
} from '@solana/web3.js'
const connection = new Connection(
'https://<primary-rpc-endpoint>',
'confirmed',
)
const nonceAuthority = Keypair.fromSecretKey(/* secret key */)- อํานาจที่ไม่มีอํานาจสามารถดําเนินการ
nonceAdvance - มันอาจจะเป็นค่าธรรมเนียม หรือค่ากุญแจแยก
ขั้นที่ 2: สร้างบัญชีที่ขาดหาย
บัญชีเงินลงทุนเป็นบัญชีของสหรัฐ
typescript
const nonceAccount = Keypair.generate()const nonceAccount = Keypair.generate()ปุ่มพิมพ์นี้ใช้สําหรับ:
- แทนค่าด้วยเลขศูนย์ (ค่าเดิม)
recentBlockhash) - ลงนามเฉพาะในเวลาการสร้างเท่านั้น
- การ เก็บ ของ หลัง จาก นั้น ปลอด ภัย; ไม่ จําเป็น ต้อง ส่ง ไป ทุก วัน
ขั้นที่ 3: คํานวณการเช่าที่น้อยที่สุด
บัญชีที่ยกเลิกต้องขาดการเช่า อย่าใช้ฮาร์ดโค้ด เรียกมาจาก RPC.
typescript
const lamports =
await connection.getMinimumBalanceForRentExemption(
NONCE_ACCOUNT_LENGTH,
)const lamports =
await connection.getMinimumBalanceForRentExemption(
NONCE_ACCOUNT_LENGTH,
)ขั้น ที่ 4: สร้าง และ เริ่ม ต้น เรื่อง ราว
สร้างบัญชีที่ไม่มีการเซ็นรับรองด้วย ~ สร้าง Account + ancess Initiative ~ ในการทําธุรกรรมครั้งเดียว
typescript
import { Transaction } from '@solana/web3.js'
const tx = new Transaction()
tx.add(
SystemProgram.createAccount({
fromPubkey: nonceAuthority.publicKey,
newAccountPubkey: nonceAccount.publicKey,
lamports,
space: NONCE_ACCOUNT_LENGTH,
programId: SystemProgram.programId,
}),
SystemProgram.nonceInitialize({
noncePubkey: nonceAccount.publicKey,
authorizedPubkey: nonceAuthority.publicKey,
}),
)
// fee payer is the nonce authority
tx.feePayer = nonceAuthority.publicKey
// use a normal blockhash for initialization
const { blockhash, lastValidBlockHeight } =
await connection.getLatestBlockhash('confirmed')
tx.recentBlockhash = blockhash
// sign with both the new account and the authority
tx.sign(nonceAccount, nonceAuthority)
const signature = await connection.sendRawTransaction(tx.serialize())
await connection.confirmTransaction(
{ signature, blockhash, lastValidBlockHeight },
'confirmed',
)import { Transaction } from '@solana/web3.js'
const tx = new Transaction()
tx.add(
SystemProgram.createAccount({
fromPubkey: nonceAuthority.publicKey,
newAccountPubkey: nonceAccount.publicKey,
lamports,
space: NONCE_ACCOUNT_LENGTH,
programId: SystemProgram.programId,
}),
SystemProgram.nonceInitialize({
noncePubkey: nonceAccount.publicKey,
authorizedPubkey: nonceAuthority.publicKey,
}),
)
// fee payer is the nonce authority
tx.feePayer = nonceAuthority.publicKey
// use a normal blockhash for initialization
const { blockhash, lastValidBlockHeight } =
await connection.getLatestBlockhash('confirmed')
tx.recentBlockhash = blockhash
// sign with both the new account and the authority
tx.sign(nonceAccount, nonceAuthority)
const signature = await connection.sendRawTransaction(tx.serialize())
await connection.confirmTransaction(
{ signature, blockhash, lastValidBlockHeight },
'confirmed',
)ใช้นี่สิ
nonceAccount.publicKey สําหรับที่ส่งมาขั้น ที่ 5: เชิญ รับ ความ สนใจ ก่อน ที่ แต่ ละ คน จะ ส่ง
สําหรับทุกรายการ ให้เรียกค่าปัจจุบัน
typescript
import { NonceAccount } from '@solana/web3.js'
const { value, context } =
await connection.getAccountInfoAndContext(
nonceAccount.publicKey,
'confirmed',
)
if (!value) {
throw new Error('Nonce account not found')
}
const nonce = NonceAccount.fromAccountData(value.data).nonce
const minContextSlot = context.slotimport { NonceAccount } from '@solana/web3.js'
const { value, context } =
await connection.getAccountInfoAndContext(
nonceAccount.publicKey,
'confirmed',
)
if (!value) {
throw new Error('Nonce account not found')
}
const nonce = NonceAccount.fromAccountData(value.data).nonce
const minContextSlot = context.slot- ใช้
nonceasrecentBlockhash context.slotใช้ในการตรวจสอบสิทธิ์
ขั้น ที่ 6: สร้าง การ ทํา การ ซื้อ ขาย ที่ ดู แล ได้
ธุรกรรมที่ดูง่ายจะต้องเป็นไปตามเงื่อนไขต่อไปนี้:
recentBlockhash = nonce- บทเรียนแรกคือ
nonceAdvance
typescript
import {
TransactionMessage,
VersionedTransaction,
} from '@solana/web3.js'
const instructions = [
SystemProgram.nonceAdvance({
noncePubkey: nonceAccount.publicKey,
authorizedPubkey: nonceAuthority.publicKey,
}),
// add your real instructions after this
]
const message = new TransactionMessage({
payerKey: nonceAuthority.publicKey,
recentBlockhash: nonce,
instructions,
}).compileToV0Message()
const tx = new VersionedTransaction(message)
tx.sign([nonceAuthority /* + other signers */])
const rawTx = tx.serialize()import {
TransactionMessage,
VersionedTransaction,
} from '@solana/web3.js'
const instructions = [
SystemProgram.nonceAdvance({
noncePubkey: nonceAccount.publicKey,
authorizedPubkey: nonceAuthority.publicKey,
}),
// add your real instructions after this
]
const message = new TransactionMessage({
payerKey: nonceAuthority.publicKey,
recentBlockhash: nonce,
instructions,
}).compileToV0Message()
const tx = new VersionedTransaction(message)
tx.sign([nonceAuthority /* + other signers */])
const rawTx = tx.serialize()บันทึกย่อ:
- ถ้าคุณใช้คําสั่งคอมมิทบรุต พวกมันก็ต้องมาหลังจากนั้น
nonceAdvance - If
nonceAdvanceไม่ใช่ครั้งแรก การซื้อขายจะถูกปฏิเสธ
ขั้นที่ 7: ออกสู่ RPC หลาย
ส่งดิบๆ มาพร้อมกัน
typescript
const endpoints = [
'https://<erpc-swqos-fra>',
'https://<backup-rpc-1>',
'https://<backup-rpc-2>',
]
const results = await Promise.allSettled(
endpoints.map((url) =>
new Connection(url, 'confirmed').sendRawTransaction(rawTx, {
skipPreflight: true,
minContextSlot,
}),
),
)
const success = results.find(
(r): r is PromiseFulfilledResult<string> =>
r.status === 'fulfilled',
)
if (!success) {
throw new Error('All sends failed')
}
const signature = success.valueconst endpoints = [
'https://<erpc-swqos-fra>',
'https://<backup-rpc-1>',
'https://<backup-rpc-2>',
]
const results = await Promise.allSettled(
endpoints.map((url) =>
new Connection(url, 'confirmed').sendRawTransaction(rawTx, {
skipPreflight: true,
minContextSlot,
}),
),
)
const success = results.find(
(r): r is PromiseFulfilledResult<string> =>
r.status === 'fulfilled',
)
if (!success) {
throw new Error('All sends failed')
}
const signature = success.value- ลายเซ็นมีลายเซ็นเหมือนกัน
- การส่งที่ประสบความสําเร็จคือ ไม่! ยืนยัน
ขั้นที่ 8: ยืนยันกับคํานามที่ดูง่าย
กับ Duorable Nosen รวมข้อมูลการไม่ขึ้นทะเบียน
typescript
await connection.confirmTransaction(
{
signature,
nonceAccountPubkey: nonceAccount.publicKey,
nonceValue: nonce,
minContextSlot,
},
'confirmed',
)await connection.confirmTransaction(
{
signature,
nonceAccountPubkey: nonceAccount.publicKey,
nonceValue: nonce,
minContextSlot,
},
'confirmed',
)หากการยืนยันล้มเหลว:
- ความไม่สงบก้าวหน้า
- ทําสําเนาจดหมายที่ส่งกลับไปยัง RPC อื่น ๆ
InvalidNonce
ส่งถัดไป
- หลังจากยืนยันแล้ว ให้เรียกที่ทําการใหม่
- อย่าใช้ค่าดิบหรือค่านวมเดิม
- สําหรับข้อมูลการกระจ่ายงานแบบขนาน ให้ใช้บัญชีที่แยกต่างหาก
สําหรับการทําธุรกรรมต่อไป ให้หาคําติชมที่ทันสมัย และสร้างรายการโดยใช้ขั้นตอนเดียวกัน